From e6a298c8b4e9bb09f6768ffa8ec6a73b057ce863 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Fri, 13 Dec 2024 01:14:09 +0200 Subject: [PATCH 01/13] UBO consolidation. --- CMakeLists.txt | 39 +- bazel/core.bzl | 21 +- include/mbgl/gfx/context.hpp | 4 +- include/mbgl/gfx/drawable.hpp | 4 + include/mbgl/gfx/uniform_buffer.hpp | 19 +- include/mbgl/gl/drawable_gl.hpp | 3 - include/mbgl/gl/layer_group_gl.hpp | 6 - include/mbgl/gl/uniform_buffer_gl.hpp | 3 + include/mbgl/mtl/context.hpp | 4 +- include/mbgl/mtl/drawable.hpp | 3 - include/mbgl/mtl/layer_group.hpp | 3 - include/mbgl/mtl/render_pass.hpp | 3 +- include/mbgl/mtl/uniform_buffer.hpp | 5 + include/mbgl/shaders/background_layer_ubo.hpp | 43 +- include/mbgl/shaders/circle_layer_ubo.hpp | 62 +- include/mbgl/shaders/collision_layer_ubo.hpp | 19 +- include/mbgl/shaders/common_ubo.hpp | 15 - .../shaders/custom_drawable_layer_ubo.hpp | 29 +- include/mbgl/shaders/debug_layer_ubo.hpp | 13 +- .../mbgl/shaders/fill_extrusion_layer_ubo.hpp | 53 +- include/mbgl/shaders/fill_layer_ubo.hpp | 149 ++-- .../mbgl/shaders/gl/drawable_background.hpp | 6 +- .../gl/drawable_background_pattern.hpp | 12 +- include/mbgl/shaders/gl/drawable_circle.hpp | 26 +- .../shaders/gl/drawable_collision_box.hpp | 19 +- .../shaders/gl/drawable_collision_circle.hpp | 18 +- .../gl/drawable_custom_symbol_icon.hpp | 7 +- include/mbgl/shaders/gl/drawable_debug.hpp | 12 +- include/mbgl/shaders/gl/drawable_fill.hpp | 14 +- .../shaders/gl/drawable_fill_extrusion.hpp | 34 +- .../gl/drawable_fill_extrusion_pattern.hpp | 64 +- .../mbgl/shaders/gl/drawable_fill_outline.hpp | 20 +- .../gl/drawable_fill_outline_pattern.hpp | 41 +- .../gl/drawable_fill_outline_triangulated.hpp | 9 +- .../mbgl/shaders/gl/drawable_fill_pattern.hpp | 41 +- include/mbgl/shaders/gl/drawable_heatmap.hpp | 10 +- .../shaders/gl/drawable_heatmap_texture.hpp | 12 +- .../mbgl/shaders/gl/drawable_hillshade.hpp | 5 +- .../shaders/gl/drawable_hillshade_prepare.hpp | 6 +- include/mbgl/shaders/gl/drawable_line.hpp | 36 +- .../shaders/gl/drawable_line_gradient.hpp | 38 +- .../mbgl/shaders/gl/drawable_line_pattern.hpp | 49 +- include/mbgl/shaders/gl/drawable_line_sdf.hpp | 46 +- .../gl/drawable_location_indicator.hpp | 16 + .../drawable_location_indicator_textured.hpp | 16 + include/mbgl/shaders/gl/drawable_raster.hpp | 8 +- .../mbgl/shaders/gl/drawable_symbol_icon.hpp | 37 +- .../mbgl/shaders/gl/drawable_symbol_sdf.hpp | 58 +- .../shaders/gl/drawable_symbol_sdf_text.hpp | 323 --------- .../gl/drawable_symbol_text_and_icon.hpp | 56 +- include/mbgl/shaders/heatmap_layer_ubo.hpp | 32 +- .../shaders/heatmap_texture_layer_ubo.hpp | 11 +- include/mbgl/shaders/hillshade_layer_ubo.hpp | 24 +- .../shaders/hillshade_prepare_layer_ubo.hpp | 18 +- include/mbgl/shaders/layer_ubo.hpp | 38 +- include/mbgl/shaders/line_layer_ubo.hpp | 228 ++++--- .../mbgl/shaders/location_indicator_ubo.hpp | 16 + include/mbgl/shaders/mtl/background.hpp | 158 ++++- .../mbgl/shaders/mtl/background_pattern.hpp | 97 --- include/mbgl/shaders/mtl/circle.hpp | 125 ++-- include/mbgl/shaders/mtl/clipping_mask.hpp | 43 +- include/mbgl/shaders/mtl/collision.hpp | 203 ++++++ include/mbgl/shaders/mtl/collision_box.hpp | 93 --- include/mbgl/shaders/mtl/collision_circle.hpp | 112 --- include/mbgl/shaders/mtl/common.hpp | 180 +---- .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 72 +- include/mbgl/shaders/mtl/debug.hpp | 36 +- include/mbgl/shaders/mtl/fill.hpp | 336 +++++---- include/mbgl/shaders/mtl/fill_extrusion.hpp | 270 +++++++- .../shaders/mtl/fill_extrusion_pattern.hpp | 192 ------ include/mbgl/shaders/mtl/heatmap.hpp | 77 ++- include/mbgl/shaders/mtl/heatmap_texture.hpp | 36 +- include/mbgl/shaders/mtl/hillshade.hpp | 72 +- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 75 +- include/mbgl/shaders/mtl/line.hpp | 402 ++++++----- include/mbgl/shaders/mtl/raster.hpp | 68 +- include/mbgl/shaders/mtl/shader_group.hpp | 2 +- include/mbgl/shaders/mtl/symbol.hpp | 646 ++++++++++++++++++ include/mbgl/shaders/mtl/symbol_icon.hpp | 145 ---- include/mbgl/shaders/mtl/symbol_sdf.hpp | 217 ------ .../mbgl/shaders/mtl/symbol_text_and_icon.hpp | 234 ------- include/mbgl/shaders/mtl/widevector.hpp | 50 +- include/mbgl/shaders/raster_layer_ubo.hpp | 32 +- include/mbgl/shaders/shader_defines.hpp | 97 ++- include/mbgl/shaders/shader_manifest.hpp | 4 +- include/mbgl/shaders/shader_source.hpp | 6 +- include/mbgl/shaders/symbol_layer_ubo.hpp | 48 +- include/mbgl/shaders/vulkan/background.hpp | 34 +- include/mbgl/shaders/vulkan/circle.hpp | 37 +- include/mbgl/shaders/vulkan/clipping_mask.hpp | 4 +- include/mbgl/shaders/vulkan/collision.hpp | 46 +- include/mbgl/shaders/vulkan/common.hpp | 91 +-- .../shaders/vulkan/custom_symbol_icon.hpp | 101 +++ include/mbgl/shaders/vulkan/debug.hpp | 8 +- include/mbgl/shaders/vulkan/fill.hpp | 536 ++------------- .../mbgl/shaders/vulkan/fill_extrusion.hpp | 391 +++++++++++ include/mbgl/shaders/vulkan/heatmap.hpp | 76 +-- .../mbgl/shaders/vulkan/heatmap_texture.hpp | 72 ++ include/mbgl/shaders/vulkan/hillshade.hpp | 133 +--- .../mbgl/shaders/vulkan/hillshade_prepare.hpp | 130 ++++ include/mbgl/shaders/vulkan/line.hpp | 171 ++--- .../shaders/vulkan/location_indicator.hpp | 87 +++ include/mbgl/shaders/vulkan/raster.hpp | 6 +- include/mbgl/shaders/vulkan/symbol.hpp | 325 +++------ include/mbgl/shaders/vulkan/widevector.hpp | 2 +- include/mbgl/shaders/widevector_ubo.hpp | 47 +- include/mbgl/vulkan/uniform_buffer.hpp | 4 +- shaders/drawable.background.fragment.glsl | 6 +- .../drawable.background_pattern.fragment.glsl | 5 +- .../drawable.background_pattern.vertex.glsl | 7 +- shaders/drawable.circle.vertex.glsl | 26 +- shaders/drawable.collision_box.fragment.glsl | 7 - shaders/drawable.collision_box.vertex.glsl | 10 +- .../drawable.collision_circle.fragment.glsl | 8 +- shaders/drawable.collision_circle.vertex.glsl | 10 +- .../drawable.custom.symbol_icon.vertex.glsl | 7 +- shaders/drawable.debug.fragment.glsl | 6 +- shaders/drawable.debug.vertex.glsl | 6 +- shaders/drawable.fill.fragment.glsl | 5 - shaders/drawable.fill.vertex.glsl | 7 +- shaders/drawable.fill_extrusion.vertex.glsl | 34 +- ...wable.fill_extrusion_pattern.fragment.glsl | 28 +- ...rawable.fill_extrusion_pattern.vertex.glsl | 36 +- shaders/drawable.fill_outline.fragment.glsl | 6 - shaders/drawable.fill_outline.vertex.glsl | 12 +- ...rawable.fill_outline_pattern.fragment.glsl | 18 +- .../drawable.fill_outline_pattern.vertex.glsl | 21 +- ...able.fill_outline_triangulated.vertex.glsl | 9 +- shaders/drawable.fill_pattern.fragment.glsl | 18 +- shaders/drawable.fill_pattern.vertex.glsl | 21 +- shaders/drawable.heatmap.vertex.glsl | 10 +- .../drawable.heatmap_texture.fragment.glsl | 4 +- shaders/drawable.heatmap_texture.vertex.glsl | 8 +- shaders/drawable.hillshade.fragment.glsl | 3 +- shaders/drawable.hillshade.vertex.glsl | 2 - .../drawable.hillshade_prepare.fragment.glsl | 3 +- .../drawable.hillshade_prepare.vertex.glsl | 3 + shaders/drawable.line.fragment.glsl | 20 +- shaders/drawable.line.vertex.glsl | 14 +- shaders/drawable.line_gradient.fragment.glsl | 20 +- shaders/drawable.line_gradient.vertex.glsl | 16 +- shaders/drawable.line_pattern.fragment.glsl | 27 +- shaders/drawable.line_pattern.vertex.glsl | 22 +- shaders/drawable.line_sdf.fragment.glsl | 27 +- shaders/drawable.line_sdf.vertex.glsl | 19 +- shaders/drawable.raster.fragment.glsl | 4 +- shaders/drawable.raster.vertex.glsl | 4 +- shaders/drawable.symbol_icon.fragment.glsl | 12 +- shaders/drawable.symbol_icon.vertex.glsl | 25 +- shaders/drawable.symbol_sdf.fragment.glsl | 25 +- shaders/drawable.symbol_sdf.vertex.glsl | 33 +- ...rawable.symbol_text_and_icon.fragment.glsl | 25 +- .../drawable.symbol_text_and_icon.vertex.glsl | 31 +- shaders/manifest.json | 30 +- src/mbgl/gfx/uniform_buffer.cpp | 19 +- src/mbgl/gl/context.cpp | 19 +- src/mbgl/gl/drawable_gl.cpp | 32 +- src/mbgl/gl/layer_group_gl.cpp | 56 +- src/mbgl/gl/uniform_buffer_gl.cpp | 27 + src/mbgl/mtl/context.cpp | 22 +- src/mbgl/mtl/drawable.cpp | 32 +- src/mbgl/mtl/layer_group.cpp | 15 +- src/mbgl/mtl/render_pass.cpp | 8 + src/mbgl/mtl/renderer_backend.cpp | 10 +- src/mbgl/mtl/tile_layer_group.cpp | 15 +- src/mbgl/mtl/uniform_buffer.cpp | 23 +- .../layers/background_layer_tweaker.cpp | 86 ++- .../layers/background_layer_tweaker.hpp | 5 + .../renderer/layers/circle_layer_tweaker.cpp | 55 +- .../renderer/layers/circle_layer_tweaker.hpp | 4 + .../layers/collision_layer_tweaker.cpp | 17 +- .../layers/fill_extrusion_layer_tweaker.cpp | 57 +- .../layers/fill_extrusion_layer_tweaker.hpp | 7 +- .../renderer/layers/fill_layer_tweaker.cpp | 173 +++-- .../renderer/layers/fill_layer_tweaker.hpp | 5 + .../renderer/layers/heatmap_layer_tweaker.cpp | 43 +- .../renderer/layers/heatmap_layer_tweaker.hpp | 4 + .../layers/heatmap_texture_layer_tweaker.cpp | 14 +- .../layers/hillshade_layer_tweaker.cpp | 56 +- .../layers/hillshade_layer_tweaker.hpp | 5 + .../hillshade_prepare_layer_tweaker.cpp | 12 +- .../renderer/layers/line_layer_tweaker.cpp | 234 ++++--- .../renderer/layers/line_layer_tweaker.hpp | 5 + .../location_indicator_layer_tweaker.cpp | 39 +- .../renderer/layers/raster_layer_tweaker.cpp | 33 +- .../renderer/layers/raster_layer_tweaker.hpp | 4 + .../render_location_indicator_layer.cpp | 6 +- .../renderer/layers/symbol_layer_tweaker.cpp | 150 ++-- .../renderer/layers/symbol_layer_tweaker.hpp | 19 +- src/mbgl/renderer/paint_parameters.cpp | 24 +- src/mbgl/renderer/renderer_impl.cpp | 4 +- .../renderer/sources/render_tile_source.cpp | 130 ++-- src/mbgl/shaders/gl/shader_info.cpp | 32 +- src/mbgl/shaders/mtl/background.cpp | 31 +- src/mbgl/shaders/mtl/background_pattern.cpp | 22 - src/mbgl/shaders/mtl/circle.cpp | 9 +- src/mbgl/shaders/mtl/clipping_mask.cpp | 8 +- src/mbgl/shaders/mtl/collision.cpp | 43 ++ src/mbgl/shaders/mtl/collision_box.cpp | 20 - src/mbgl/shaders/mtl/collision_circle.cpp | 22 - src/mbgl/shaders/mtl/custom_symbol_icon.cpp | 16 +- src/mbgl/shaders/mtl/debug.cpp | 10 +- src/mbgl/shaders/mtl/fill.cpp | 75 +- src/mbgl/shaders/mtl/fill_extrusion.cpp | 36 +- .../shaders/mtl/fill_extrusion_pattern.cpp | 32 - src/mbgl/shaders/mtl/heatmap.cpp | 9 +- src/mbgl/shaders/mtl/heatmap_texture.cpp | 10 +- src/mbgl/shaders/mtl/hillshade.cpp | 11 +- src/mbgl/shaders/mtl/hillshade_prepare.cpp | 18 +- src/mbgl/shaders/mtl/line.cpp | 59 +- src/mbgl/shaders/mtl/raster.cpp | 8 +- src/mbgl/shaders/mtl/symbol.cpp | 94 +++ src/mbgl/shaders/mtl/symbol_icon.cpp | 30 - src/mbgl/shaders/mtl/symbol_sdf.cpp | 36 - src/mbgl/shaders/mtl/symbol_text_and_icon.cpp | 36 - src/mbgl/shaders/mtl/widevector.cpp | 27 + src/mbgl/shaders/vulkan/background.cpp | 34 +- src/mbgl/shaders/vulkan/circle.cpp | 8 +- src/mbgl/shaders/vulkan/clipping_mask.cpp | 9 +- src/mbgl/shaders/vulkan/collision.cpp | 29 +- src/mbgl/shaders/vulkan/common.cpp | 28 - .../shaders/vulkan/custom_symbol_icon.cpp | 22 + src/mbgl/shaders/vulkan/debug.cpp | 8 +- src/mbgl/shaders/vulkan/fill.cpp | 109 ++- src/mbgl/shaders/vulkan/fill_extrusion.cpp | 50 ++ src/mbgl/shaders/vulkan/heatmap.cpp | 23 +- src/mbgl/shaders/vulkan/heatmap_texture.cpp | 23 + src/mbgl/shaders/vulkan/hillshade.cpp | 23 +- src/mbgl/shaders/vulkan/hillshade_prepare.cpp | 22 + src/mbgl/shaders/vulkan/line.cpp | 70 +- .../shaders/vulkan/location_indicator.cpp | 38 ++ src/mbgl/shaders/vulkan/raster.cpp | 8 +- src/mbgl/shaders/vulkan/symbol.cpp | 90 ++- src/mbgl/shaders/vulkan/widevector.cpp | 22 +- .../style/layers/custom_drawable_layer.cpp | 135 ++-- src/mbgl/vulkan/context.cpp | 12 +- src/mbgl/vulkan/renderer_backend.cpp | 10 +- src/mbgl/vulkan/uniform_buffer.cpp | 12 +- test/util/hash.test.cpp | 9 +- 239 files changed, 6121 insertions(+), 5871 deletions(-) delete mode 100644 include/mbgl/shaders/common_ubo.hpp create mode 100644 include/mbgl/shaders/gl/drawable_location_indicator.hpp create mode 100644 include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp delete mode 100644 include/mbgl/shaders/gl/drawable_symbol_sdf_text.hpp create mode 100644 include/mbgl/shaders/location_indicator_ubo.hpp delete mode 100644 include/mbgl/shaders/mtl/background_pattern.hpp create mode 100644 include/mbgl/shaders/mtl/collision.hpp delete mode 100644 include/mbgl/shaders/mtl/collision_box.hpp delete mode 100644 include/mbgl/shaders/mtl/collision_circle.hpp delete mode 100644 include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp create mode 100644 include/mbgl/shaders/mtl/symbol.hpp delete mode 100644 include/mbgl/shaders/mtl/symbol_icon.hpp delete mode 100644 include/mbgl/shaders/mtl/symbol_sdf.hpp delete mode 100644 include/mbgl/shaders/mtl/symbol_text_and_icon.hpp create mode 100644 include/mbgl/shaders/vulkan/custom_symbol_icon.hpp create mode 100644 include/mbgl/shaders/vulkan/fill_extrusion.hpp create mode 100644 include/mbgl/shaders/vulkan/heatmap_texture.hpp create mode 100644 include/mbgl/shaders/vulkan/hillshade_prepare.hpp create mode 100644 include/mbgl/shaders/vulkan/location_indicator.hpp delete mode 100644 src/mbgl/shaders/mtl/background_pattern.cpp create mode 100644 src/mbgl/shaders/mtl/collision.cpp delete mode 100644 src/mbgl/shaders/mtl/collision_box.cpp delete mode 100644 src/mbgl/shaders/mtl/collision_circle.cpp delete mode 100644 src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp create mode 100644 src/mbgl/shaders/mtl/symbol.cpp delete mode 100644 src/mbgl/shaders/mtl/symbol_icon.cpp delete mode 100644 src/mbgl/shaders/mtl/symbol_sdf.cpp delete mode 100644 src/mbgl/shaders/mtl/symbol_text_and_icon.cpp create mode 100644 src/mbgl/shaders/mtl/widevector.cpp delete mode 100644 src/mbgl/shaders/vulkan/common.cpp create mode 100644 src/mbgl/shaders/vulkan/custom_symbol_icon.cpp create mode 100644 src/mbgl/shaders/vulkan/fill_extrusion.cpp create mode 100644 src/mbgl/shaders/vulkan/heatmap_texture.cpp create mode 100644 src/mbgl/shaders/vulkan/hillshade_prepare.cpp create mode 100644 src/mbgl/shaders/vulkan/location_indicator.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 52267c770b0..b2b51e4dee6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1139,9 +1139,7 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/background_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/circle_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/collision_layer_ubo.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/common_ubo.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/style/layers/custom_drawable_layer.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/layermanager/custom_drawable_layer_factory.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/custom_drawable_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/debug_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/fill_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp @@ -1151,11 +1149,13 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/line_layer_ubo.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/custom_drawable_layer_ubo.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/location_indicator_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/raster_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/shader_defines.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/symbol_layer_ubo.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/widevector_ubo.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/style/layers/custom_drawable_layer.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/layermanager/custom_drawable_layer_factory.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/shader_program_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/buffer_allocator.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl.hpp @@ -1212,17 +1212,14 @@ if(MLN_WITH_METAL) ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/vertex_attribute.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/vertex_buffer_resource.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/background.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/background_pattern.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/circle.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/clipping_mask.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/common.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/collision_box.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/collision_circle.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/collision.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/custom_symbol_icon.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/debug.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/fill.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/fill_extrusion.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/heatmap.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/heatmap_texture.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/hillshade.hpp @@ -1231,9 +1228,7 @@ if(MLN_WITH_METAL) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/raster.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/shader_group.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/shader_program.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/symbol_icon.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/symbol_sdf.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/mtl/symbol.hpp ) list(APPEND SRC_FILES @@ -1258,25 +1253,21 @@ if(MLN_WITH_METAL) ${PROJECT_SOURCE_DIR}/src/mbgl/mtl/vertex_buffer_resource.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/shader_program.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/background.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/background_pattern.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/circle.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/collision_box.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/collision_circle.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/collision.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/clipping_mask.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/custom_symbol_icon.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/debug.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/fill.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/fill_extrusion.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/heatmap.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/heatmap_texture.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/hillshade.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/hillshade_prepare.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/line.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/raster.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol_icon.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol_sdf.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/widevector.cpp ) find_library(METAL_FRAMEWORK Metal) @@ -1322,11 +1313,15 @@ if(MLN_WITH_VULKAN) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/clipping_mask.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/collision.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/common.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/debug.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/fill.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/fill_extrusion.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/heatmap.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/heatmap_texture.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/hillshade.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/hillshade_prepare.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/line.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/location_indicator.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/raster.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/symbol.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/vulkan/widevector.hpp @@ -1358,12 +1353,16 @@ if(MLN_WITH_VULKAN) ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/circle.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/clipping_mask.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/collision.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/common.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/debug.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/fill.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/fill_extrusion.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/heatmap.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/heatmap_texture.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/hillshade.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/hillshade_prepare.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/line.cpp + ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/location_indicator.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/raster.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/symbol.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/shaders/vulkan/widevector.cpp diff --git a/bazel/core.bzl b/bazel/core.bzl index 472fde18105..0305c43dfd5 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -1003,7 +1003,6 @@ MLN_DRAWABLES_HEADERS = [ "include/mbgl/shaders/background_layer_ubo.hpp", "include/mbgl/shaders/circle_layer_ubo.hpp", "include/mbgl/shaders/collision_layer_ubo.hpp", - "include/mbgl/shaders/common_ubo.hpp", "include/mbgl/shaders/custom_drawable_layer_ubo.hpp", "include/mbgl/shaders/debug_layer_ubo.hpp", "include/mbgl/shaders/fill_layer_ubo.hpp", @@ -1014,6 +1013,7 @@ MLN_DRAWABLES_HEADERS = [ "include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp", "include/mbgl/shaders/layer_ubo.hpp", "include/mbgl/shaders/line_layer_ubo.hpp", + "include/mbgl/shaders/location_indicator_ubo.hpp", "include/mbgl/shaders/raster_layer_ubo.hpp", "include/mbgl/shaders/shader_defines.hpp", "include/mbgl/shaders/shader_program_base.hpp", @@ -1074,25 +1074,21 @@ MLN_DRAWABLES_MTL_SOURCE = [ "src/mbgl/mtl/vertex_buffer_resource.cpp", "src/mbgl/shaders/mtl/shader_program.cpp", "src/mbgl/shaders/mtl/background.cpp", - "src/mbgl/shaders/mtl/background_pattern.cpp", "src/mbgl/shaders/mtl/circle.cpp", - "src/mbgl/shaders/mtl/collision_box.cpp", - "src/mbgl/shaders/mtl/collision_circle.cpp", + "src/mbgl/shaders/mtl/collision.cpp", "src/mbgl/shaders/mtl/clipping_mask.cpp", "src/mbgl/shaders/mtl/custom_symbol_icon.cpp", "src/mbgl/shaders/mtl/debug.cpp", "src/mbgl/shaders/mtl/fill.cpp", "src/mbgl/shaders/mtl/fill_extrusion.cpp", - "src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp", "src/mbgl/shaders/mtl/heatmap.cpp", "src/mbgl/shaders/mtl/heatmap_texture.cpp", "src/mbgl/shaders/mtl/hillshade.cpp", "src/mbgl/shaders/mtl/hillshade_prepare.cpp", "src/mbgl/shaders/mtl/line.cpp", "src/mbgl/shaders/mtl/raster.cpp", - "src/mbgl/shaders/mtl/symbol_icon.cpp", - "src/mbgl/shaders/mtl/symbol_sdf.cpp", - "src/mbgl/shaders/mtl/symbol_text_and_icon.cpp", + "src/mbgl/shaders/mtl/symbol.cpp", + "src/mbgl/shaders/mtl/widevector.cpp", "src/mbgl/style/layers/mtl/custom_layer_render_parameters.cpp", ] @@ -1117,17 +1113,14 @@ MLN_DRAWABLES_MTL_HEADERS = [ "include/mbgl/mtl/vertex_attribute.hpp", "include/mbgl/mtl/vertex_buffer_resource.hpp", "include/mbgl/shaders/mtl/background.hpp", - "include/mbgl/shaders/mtl/background_pattern.hpp", "include/mbgl/shaders/mtl/circle.hpp", "include/mbgl/shaders/mtl/clipping_mask.hpp", - "include/mbgl/shaders/mtl/collision_box.hpp", - "include/mbgl/shaders/mtl/collision_circle.hpp", + "include/mbgl/shaders/mtl/collision.hpp", "include/mbgl/shaders/mtl/common.hpp", "include/mbgl/shaders/mtl/custom_symbol_icon.hpp", "include/mbgl/shaders/mtl/debug.hpp", "include/mbgl/shaders/mtl/fill.hpp", "include/mbgl/shaders/mtl/fill_extrusion.hpp", - "include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp", "include/mbgl/shaders/mtl/heatmap.hpp", "include/mbgl/shaders/mtl/heatmap_texture.hpp", "include/mbgl/shaders/mtl/hillshade.hpp", @@ -1136,9 +1129,7 @@ MLN_DRAWABLES_MTL_HEADERS = [ "include/mbgl/shaders/mtl/raster.hpp", "include/mbgl/shaders/mtl/shader_group.hpp", "include/mbgl/shaders/mtl/shader_program.hpp", - "include/mbgl/shaders/mtl/symbol_icon.hpp", - "include/mbgl/shaders/mtl/symbol_sdf.hpp", - "include/mbgl/shaders/mtl/symbol_text_and_icon.hpp", + "include/mbgl/shaders/mtl/symbol.hpp", "include/mbgl/style/layers/mtl/custom_layer_render_parameters.hpp", "include/mbgl/shaders/mtl/widevector.hpp", ] diff --git a/include/mbgl/gfx/context.hpp b/include/mbgl/gfx/context.hpp index 8e21265098f..e2f8302d064 100644 --- a/include/mbgl/gfx/context.hpp +++ b/include/mbgl/gfx/context.hpp @@ -125,7 +125,9 @@ class Context { /// @param data The data to copy, may be `nullptr` /// @param size The size of the buffer /// @param persistent Performance hint, optimize for few or many uses - virtual UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false) = 0; + virtual UniformBufferPtr createUniformBuffer(const void* data, + std::size_t size, + bool persistent = false) = 0; /// Get the generic shader with the specified name virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0; diff --git a/include/mbgl/gfx/drawable.hpp b/include/mbgl/gfx/drawable.hpp index 5d4f324fa1a..d820040dbea 100644 --- a/include/mbgl/gfx/drawable.hpp +++ b/include/mbgl/gfx/drawable.hpp @@ -251,6 +251,9 @@ class Drawable { /// Get drawable user-defined type size_t getType() const { return type; } + void setUBOIndex(uint32_t uboIndex_) { uboIndex = uboIndex_; } + uint32_t getUBOIndex() const { return uboIndex; } + /// Associate the drawable with a layer tweaker. This is used to manage the lifetime of the tweaker. void setLayerTweaker(LayerTweakerPtr tweaker) { layerTweaker = std::move(tweaker); } const LayerTweakerPtr& getLayerTweaker() const { return layerTweaker; } @@ -305,6 +308,7 @@ class Drawable { std::size_t type = 0; std::optional> origin; + uint32_t uboIndex = 0; }; using DrawablePtr = std::shared_ptr; diff --git a/include/mbgl/gfx/uniform_buffer.hpp b/include/mbgl/gfx/uniform_buffer.hpp index d1acdc94ae2..72ef7f0102f 100644 --- a/include/mbgl/gfx/uniform_buffer.hpp +++ b/include/mbgl/gfx/uniform_buffer.hpp @@ -41,8 +41,17 @@ class UniformBuffer { return *this; } +public: + bool getBindVertex() const { return bindVertex; } + void setBindVertex(bool value) { bindVertex = value; } + + bool getBindFragment() const { return bindFragment; } + void setBindFragment(bool value) { bindFragment = value; } + protected: std::size_t size; + bool bindVertex = false; + bool bindFragment = false; }; /// Stores a collection of uniform buffers by id @@ -62,17 +71,17 @@ class UniformBufferArray { const std::shared_ptr& get(const size_t id) const; /// Set a new uniform buffer element or replace the existing one. - virtual const std::shared_ptr& set(const size_t id, std::shared_ptr uniformBuffer); + virtual const std::shared_ptr& set(const size_t id, std::shared_ptr uniformBuffer, bool bindVertex, bool bindFragment); /// Create and add a new buffer or update an existing one - void createOrUpdate(const size_t id, const std::vector& data, gfx::Context&, bool persistent = false); + void createOrUpdate(const size_t id, const std::vector& data, gfx::Context&, bool bindVertex, bool bindFragment); virtual void createOrUpdate( - const size_t id, const void* data, std::size_t size, gfx::Context&, bool persistent = false); + const size_t id, const void* data, std::size_t size, gfx::Context&, bool bindVertex, bool bindFragment); template - void createOrUpdate(const size_t id, const T* data, gfx::Context& context, bool persistent = false) + void createOrUpdate(const size_t id, const T* data, gfx::Context& context, bool bindVertex, bool bindFragment) requires(!std::is_pointer_v) { - createOrUpdate(id, data, sizeof(T), context, persistent); + createOrUpdate(id, data, sizeof(T), context, bindVertex, bindFragment); } UniformBufferArray& operator=(UniformBufferArray&&); diff --git a/include/mbgl/gl/drawable_gl.hpp b/include/mbgl/gl/drawable_gl.hpp index f088003dca1..2aad6c4d8b1 100644 --- a/include/mbgl/gl/drawable_gl.hpp +++ b/include/mbgl/gl/drawable_gl.hpp @@ -68,9 +68,6 @@ class DrawableGL : public gfx::Drawable { void uploadTextures() const; - void bindUniformBuffers() const; - void unbindUniformBuffers() const; - void bindTextures() const; void unbindTextures() const; }; diff --git a/include/mbgl/gl/layer_group_gl.hpp b/include/mbgl/gl/layer_group_gl.hpp index 0250a854580..5a4553d1d5e 100644 --- a/include/mbgl/gl/layer_group_gl.hpp +++ b/include/mbgl/gl/layer_group_gl.hpp @@ -24,9 +24,6 @@ class TileLayerGroupGL : public TileLayerGroup { gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; }; - void bindUniformBuffers() const; - void unbindUniformBuffers() const; - protected: UniformBufferArrayGL uniformBuffers; }; @@ -46,9 +43,6 @@ class LayerGroupGL : public LayerGroup { gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; }; - void bindUniformBuffers() const; - void unbindUniformBuffers() const; - protected: UniformBufferArrayGL uniformBuffers; }; diff --git a/include/mbgl/gl/uniform_buffer_gl.hpp b/include/mbgl/gl/uniform_buffer_gl.hpp index 870b2d4333d..5d1361a6a5d 100644 --- a/include/mbgl/gl/uniform_buffer_gl.hpp +++ b/include/mbgl/gl/uniform_buffer_gl.hpp @@ -58,6 +58,9 @@ class UniformBufferArrayGL final : public gfx::UniformBufferArray { UniformBufferArray::operator=(other); return *this; } + + void bind() const; + void unbind() const; private: std::unique_ptr copy(const gfx::UniformBuffer& uniformBuffers) override { diff --git a/include/mbgl/mtl/context.hpp b/include/mbgl/mtl/context.hpp index cf1be121ee5..f1c9e7e5130 100644 --- a/include/mbgl/mtl/context.hpp +++ b/include/mbgl/mtl/context.hpp @@ -83,7 +83,9 @@ class Context final : public gfx::Context { void reduceMemoryUsage() override {} gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override; - gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent) override; + gfx::UniformBufferPtr createUniformBuffer(const void* data, + std::size_t size, + bool persisten) override; gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override; diff --git a/include/mbgl/mtl/drawable.hpp b/include/mbgl/mtl/drawable.hpp index 7abc899197a..b40c87b76e1 100644 --- a/include/mbgl/mtl/drawable.hpp +++ b/include/mbgl/mtl/drawable.hpp @@ -73,9 +73,6 @@ class Drawable : public gfx::Drawable { void bindInstanceAttributes(RenderPass&) const noexcept; - void bindUniformBuffers(RenderPass&) const noexcept; - void unbindUniformBuffers(RenderPass&) const noexcept {} - void bindTextures(RenderPass&) const noexcept; void unbindTextures(RenderPass&) const noexcept; diff --git a/include/mbgl/mtl/layer_group.hpp b/include/mbgl/mtl/layer_group.hpp index 90f742942c6..818ebb53322 100644 --- a/include/mbgl/mtl/layer_group.hpp +++ b/include/mbgl/mtl/layer_group.hpp @@ -26,9 +26,6 @@ class LayerGroup : public mbgl::LayerGroup { gfx::UniformBufferArray& mutableUniformBuffers() override { return uniformBuffers; }; - void bindUniformBuffers(RenderPass&) const noexcept; - void unbindUniformBuffers(RenderPass&) const noexcept {} - protected: UniformBufferArray uniformBuffers; }; diff --git a/include/mbgl/mtl/render_pass.hpp b/include/mbgl/mtl/render_pass.hpp index e13d6b5f576..35ae8ffd2f3 100644 --- a/include/mbgl/mtl/render_pass.hpp +++ b/include/mbgl/mtl/render_pass.hpp @@ -45,8 +45,9 @@ class RenderPass final : public gfx::RenderPass { void addDebugSignpost(const char* name) override; void bindVertex(const BufferResource&, std::size_t offset, std::size_t index, std::size_t size = 0); - + void unbindVertex(std::size_t index); void bindFragment(const BufferResource&, std::size_t offset, std::size_t index, std::size_t size = 0); + void unbindFragment(std::size_t index); private: void pushDebugGroup(const char* name) override; diff --git a/include/mbgl/mtl/uniform_buffer.hpp b/include/mbgl/mtl/uniform_buffer.hpp index 8e5c9735684..fdfbb31ff5b 100644 --- a/include/mbgl/mtl/uniform_buffer.hpp +++ b/include/mbgl/mtl/uniform_buffer.hpp @@ -6,6 +6,8 @@ namespace mbgl { namespace mtl { +class RenderPass; + class UniformBuffer final : public gfx::UniformBuffer { public: UniformBuffer(BufferResource&&); @@ -40,6 +42,9 @@ class UniformBufferArray final : public gfx::UniformBufferArray { return *this; } + void bind(RenderPass& renderPass) const noexcept; + void unbind(RenderPass& renderPass) const noexcept {}; + private: gfx::UniqueUniformBuffer copy(const gfx::UniformBuffer& buffer) override { return std::make_unique(static_cast(buffer).clone()); diff --git a/include/mbgl/shaders/background_layer_ubo.hpp b/include/mbgl/shaders/background_layer_ubo.hpp index 9f31256e0a9..7c0e19aa27e 100644 --- a/include/mbgl/shaders/background_layer_ubo.hpp +++ b/include/mbgl/shaders/background_layer_ubo.hpp @@ -11,31 +11,39 @@ namespace shaders { // Background struct alignas(16) BackgroundDrawableUBO { - std::array matrix; + /* 0 */ std::array matrix; + /* 64 */ }; -static_assert(sizeof(BackgroundDrawableUBO) == 64); +static_assert(sizeof(BackgroundDrawableUBO) == 4 * 16); -struct alignas(16) BackgroundLayerUBO { +/// Evaluated properties that do not depend on the tile +struct alignas(16) BackgroundPropsUBO { /* 0 */ Color color; /* 16 */ float opacity; - /* 24 */ float pad1, pad2, pad3; + /* 20 */ float pad1; + /* 24 */ float pad2; + /* 28 */ float pad3; /* 32 */ }; -static_assert(sizeof(BackgroundLayerUBO) == 32); +static_assert(sizeof(BackgroundPropsUBO) == 2 * 16); // // Background pattern struct alignas(16) BackgroundPatternDrawableUBO { - std::array matrix; - std::array pixel_coord_upper; - std::array pixel_coord_lower; - float tile_units_to_pixels; - float pad1, pad2, pad3; + /* 0 */ std::array matrix; + /* 64 */ std::array pixel_coord_upper; + /* 72 */ std::array pixel_coord_lower; + /* 80 */ float tile_units_to_pixels; + /* 84 */ float pad1; + /* 88 */ float pad2; + /* 92 */ float pad3; + /* 96 */ }; -static_assert(sizeof(BackgroundPatternDrawableUBO) == 96); +static_assert(sizeof(BackgroundPatternDrawableUBO) == 6 * 16); -struct alignas(16) BackgroundPatternLayerUBO { +/// Evaluated properties that do not depend on the tile +struct alignas(16) BackgroundPatternPropsUBO { /* 0 */ std::array pattern_tl_a; /* 8 */ std::array pattern_br_a; /* 16 */ std::array pattern_tl_b; @@ -48,7 +56,16 @@ struct alignas(16) BackgroundPatternLayerUBO { /* 60 */ float opacity; /* 64 */ }; -static_assert(sizeof(BackgroundPatternLayerUBO) == 64); +static_assert(sizeof(BackgroundPatternPropsUBO) == 4 * 16); + +#if MLN_UBO_CONSOLIDATION + +union BackgroundDrawableUnionUBO { + BackgroundDrawableUBO backgroundDrawableUBO; + BackgroundPatternDrawableUBO backgroundPatternDrawableUBO; +}; + +#endif } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/circle_layer_ubo.hpp b/include/mbgl/shaders/circle_layer_ubo.hpp index 9c347b807e1..27a7a5d87e6 100644 --- a/include/mbgl/shaders/circle_layer_ubo.hpp +++ b/include/mbgl/shaders/circle_layer_ubo.hpp @@ -6,45 +6,39 @@ namespace mbgl { namespace shaders { struct alignas(16) CircleDrawableUBO { - /* 0 */ std::array matrix; // composite model-view-projection matrix - /* 64 */ std::array extrude_scale; - /* 72 */ float pad; - /* 80 */ -}; -static_assert(sizeof(CircleDrawableUBO) == 5 * 16); + /* 0 */ std::array matrix; + /* 64 */ std::array extrude_scale; -struct alignas(16) CirclePaintParamsUBO { - /* 0 */ float camera_to_center_distance; - /* 4 */ float pad1, pad2, pad3; - /* 16 */ + // Interpolations + /* 72 */ float color_t; + /* 76 */ float radius_t; + /* 80 */ float blur_t; + /* 84 */ float opacity_t; + /* 88 */ float stroke_color_t; + /* 92 */ float stroke_width_t; + /* 96 */ float stroke_opacity_t; + /* 100 */ float pad1; + /* 104 */ float pad2; + /* 108 */ float pad3; + /* 112 */ }; -static_assert(sizeof(CirclePaintParamsUBO) == 1 * 16); +static_assert(sizeof(CircleDrawableUBO) == 7 * 16); +/// Evaluated properties that do not depend on the tile struct alignas(16) CircleEvaluatedPropsUBO { - Color color; - Color stroke_color; - float radius; - float blur; - float opacity; - float stroke_width; - float stroke_opacity; - int scale_with_map; - int pitch_with_map; - float padding; -}; -static_assert(sizeof(CircleEvaluatedPropsUBO) % 16 == 0); - -struct alignas(16) CircleInterpolateUBO { - float color_t; - float radius_t; - float blur_t; - float opacity_t; - float stroke_color_t; - float stroke_width_t; - float stroke_opacity_t; - float padding; + /* 0 */ Color color; + /* 16 */ Color stroke_color; + /* 32 */ float radius; + /* 36 */ float blur; + /* 40 */ float opacity; + /* 44 */ float stroke_width; + /* 48 */ float stroke_opacity; + /* 52 */ int scale_with_map; + /* 56 */ int pitch_with_map; + /* 60 */ float pad1; + /* 64 */ }; -static_assert(sizeof(CircleInterpolateUBO) % 16 == 0); +static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/collision_layer_ubo.hpp b/include/mbgl/shaders/collision_layer_ubo.hpp index d185fa0c031..3bd073c7302 100644 --- a/include/mbgl/shaders/collision_layer_ubo.hpp +++ b/include/mbgl/shaders/collision_layer_ubo.hpp @@ -5,14 +5,19 @@ namespace mbgl { namespace shaders { -struct alignas(16) CollisionUBO { - std::array matrix; - std::array extrude_scale; - float overscale_factor; - float pad; +struct alignas(16) CollisionDrawableUBO { + /* 0 */ std::array matrix; + /* 64 */ }; -static_assert(sizeof(CollisionUBO) % 16 == 0); -static_assert(sizeof(CollisionUBO) == 80); +static_assert(sizeof(CollisionDrawableUBO) == 4 * 16); + +struct alignas(16) CollisionTilePropsUBO { + /* 0 */ std::array extrude_scale; + /* 8 */ float overscale_factor; + /* 12 */ float pad1; + /* 16 */ +}; +static_assert(sizeof(CollisionTilePropsUBO) == 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/common_ubo.hpp b/include/mbgl/shaders/common_ubo.hpp deleted file mode 100644 index cb97cbfbdbe..00000000000 --- a/include/mbgl/shaders/common_ubo.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -namespace mbgl { -namespace shaders { - -struct alignas(16) CommonUBO { - std::array matrix; - Color color; -}; -static_assert(sizeof(CommonUBO) % 16 == 0); - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/custom_drawable_layer_ubo.hpp b/include/mbgl/shaders/custom_drawable_layer_ubo.hpp index b022a52b90c..81cea47a546 100644 --- a/include/mbgl/shaders/custom_drawable_layer_ubo.hpp +++ b/include/mbgl/shaders/custom_drawable_layer_ubo.hpp @@ -5,26 +5,21 @@ namespace mbgl { namespace shaders { -/// Custom Symbol Icon matrix struct alignas(16) CustomSymbolIconDrawableUBO { /* 0 */ std::array matrix; - /* 64 */ + /* 64 */ std::array extrude_scale; + /* 72 */ std::array anchor; + /* 80 */ float angle_degrees; + /* 84 */ uint32_t scale_with_map; + /* 88 */ uint32_t pitch_with_map; + /* 92 */ float camera_to_center_distance; + /* 96 */ float aspect_ratio; + /* 100 */ float pad1; + /* 104 */ float pad2; + /* 108 */ float pad3; + /* 112 */ }; -static_assert(sizeof(CustomSymbolIconDrawableUBO) == 4 * 16); - -/// Custom Symbol Icon Parameters -struct alignas(16) CustomSymbolIconParametersUBO { - /* 0 */ std::array extrude_scale; - /* 8 */ std::array anchor; - /* 16 */ float angle_degrees; - /* 20 */ uint32_t scale_with_map; - /* 24 */ uint32_t pitch_with_map; - /* 28 */ float camera_to_center_distance; - /* 32 */ float aspect_ratio; - /* 36 */ float pad0, pad1, pad2; - /* 48 */ -}; -static_assert(sizeof(CustomSymbolIconParametersUBO) == 3 * 16); +static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/debug_layer_ubo.hpp b/include/mbgl/shaders/debug_layer_ubo.hpp index d0f6adffa38..577be4c9d5a 100644 --- a/include/mbgl/shaders/debug_layer_ubo.hpp +++ b/include/mbgl/shaders/debug_layer_ubo.hpp @@ -6,12 +6,15 @@ namespace mbgl { namespace shaders { struct alignas(16) DebugUBO { - std::array matrix; - Color color; - float overlay_scale; - float pad1, pad2, pad3; + /* 0 */ std::array matrix; + /* 64 */ Color color; + /* 80 */ float overlay_scale; + /* 84 */ float pad1; + /* 88 */ float pad2; + /* 92 */ float pad3; + /* 96 */ }; -static_assert(sizeof(DebugUBO) % 16 == 0); +static_assert(sizeof(DebugUBO) == 6 * 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp index 2a748fbc305..8213ea077b2 100644 --- a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp @@ -8,15 +8,32 @@ namespace mbgl { namespace shaders { struct alignas(16) FillExtrusionDrawableUBO { - /* 0 */ std::array matrix; - /* 64 */ std::array texsize; - /* 72 */ std::array pixel_coord_upper; - /* 80 */ std::array pixel_coord_lower; - /* 88 */ float height_factor; - /* 92 */ float tile_ratio; - /* 96 */ + /* 0 */ std::array matrix; + /* 64 */ std::array pixel_coord_upper; + /* 72 */ std::array pixel_coord_lower; + /* 80 */ float height_factor; + /* 84 */ float tile_ratio; + + // Interpolations + /* 88 */ float base_t; + /* 92 */ float height_t; + /* 96 */ float color_t; + /* 100 */ float pattern_from_t; + /* 104 */ float pattern_to_t; + /* 108 */ float pad1; + /* 112 */ }; -static_assert(sizeof(FillExtrusionDrawableUBO) == 6 * 16); +static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16); + +struct alignas(16) FillExtrusionTilePropsUBO { + /* 0 */ std::array pattern_from; + /* 16 */ std::array pattern_to; + /* 32 */ std::array texsize; + /* 40 */ float pad1; + /* 44 */ float pad2; + /* 48 */ +}; +static_assert(sizeof(FillExtrusionTilePropsUBO) == 3 * 16); /// Evaluated properties that do not depend on the tile struct alignas(16) FillExtrusionPropsUBO { @@ -37,25 +54,5 @@ struct alignas(16) FillExtrusionPropsUBO { }; static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16); -/// Evaluated properties that depend on the tile -struct alignas(16) FillExtrusionTilePropsUBO { - /* 0 */ std::array pattern_from; - /* 16 */ std::array pattern_to; - /* 32 */ -}; -static_assert(sizeof(FillExtrusionTilePropsUBO) == 2 * 16); - -/// Attribute interpolations -struct alignas(16) FillExtrusionInterpolateUBO { - /* 0 */ float base_t; - /* 4 */ float height_t; - /* 8 */ float color_t; - /* 12 */ float pattern_from_t; - /* 16 */ float pattern_to_t; - /* 20 */ float pad1, pad2, pad3; - /* 32 */ -}; -static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16); - } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/fill_layer_ubo.hpp b/include/mbgl/shaders/fill_layer_ubo.hpp index bcfd34ef933..dc434be19fe 100644 --- a/include/mbgl/shaders/fill_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_layer_ubo.hpp @@ -9,112 +9,127 @@ namespace shaders { // Fill struct alignas(16) FillDrawableUBO { - /* 0 */ std::array matrix; // composite model-view-projection matrix - /* 64 */ + /* 0 */ std::array matrix; + + // Interpolations + /* 64 */ float color_t; + /* 68 */ float opacity_t; + /* 72 */ float pad1; + /* 76 */ float pad2; + /* 80 */ }; -static_assert(sizeof(FillDrawableUBO) == 4 * 16); - -struct alignas(16) FillInterpolateUBO { - float color_t; - float opacity_t; - float pad1, pad2; -}; -static_assert(sizeof(FillInterpolateUBO) % 16 == 0); +static_assert(sizeof(FillDrawableUBO) == 5 * 16); // // Fill outline struct alignas(16) FillOutlineDrawableUBO { - /* 0 */ std::array matrix; // composite model-view-projection matrix - /* 64 */ + /* 0 */ std::array matrix; + + // Interpolations + /* 64 */ float outline_color_t; + /* 68 */ float opacity_t; + /* 72 */ float pad1; + /* 76 */ float pad2; + /* 80 */ }; -static_assert(sizeof(FillOutlineDrawableUBO) == 4 * 16); - -struct alignas(16) FillOutlineInterpolateUBO { - float outline_color_t; - float opacity_t; - float pad1, pad2; -}; -static_assert(sizeof(FillOutlineInterpolateUBO) == 1 * 16); +static_assert(sizeof(FillOutlineDrawableUBO) == 5 * 16); // -// Fill Pattern +// Fill pattern struct alignas(16) FillPatternDrawableUBO { - /* 0 */ std::array matrix; // composite model-view-projection matrix + /* 0 */ std::array matrix; /* 64 */ std::array pixel_coord_upper; /* 72 */ std::array pixel_coord_lower; - /* 80 */ std::array texsize; - /* 88 */ float tile_ratio; - /* 92 */ float pad; + /* 80 */ float tile_ratio; + + // Interpolations + /* 84 */ float pattern_from_t; + /* 88 */ float pattern_to_t; + /* 92 */ float opacity_t; /* 96 */ }; static_assert(sizeof(FillPatternDrawableUBO) == 6 * 16); struct alignas(16) FillPatternTilePropsUBO { - std::array pattern_from; - std::array pattern_to; -}; -static_assert(sizeof(FillPatternTilePropsUBO) == 2 * 16); - -struct alignas(16) FillPatternInterpolateUBO { - float pattern_from_t; - float pattern_to_t; - float opacity_t; - float pad1; + /* 0 */ std::array pattern_from; + /* 16 */ std::array pattern_to; + /* 32 */ std::array texsize; + /* 40 */ float pad1; + /* 44 */ float pad2; + /* 48 */ }; -static_assert(sizeof(FillPatternInterpolateUBO) == 1 * 16); +static_assert(sizeof(FillPatternTilePropsUBO) == 3 * 16); // // Fill pattern outline struct alignas(16) FillOutlinePatternDrawableUBO { - /* 0 */ std::array matrix; // composite model-view-projection matrix - /* 64 */ std::array pixel_coord_upper; - /* 72 */ std::array pixel_coord_lower; - /* 80 */ std::array texsize; - /* 88 */ float tile_ratio; - /* 92 */ float pad; - /* 96 */ + /* 0 */ std::array matrix; + /* 64 */ std::array pixel_coord_upper; + /* 72 */ std::array pixel_coord_lower; + /* 80 */ float tile_ratio; + + // Interpolations + /* 84 */ float pattern_from_t; + /* 88 */ float pattern_to_t; + /* 92 */ float opacity_t; + /* 96 */ }; static_assert(sizeof(FillOutlinePatternDrawableUBO) == 6 * 16); struct alignas(16) FillOutlinePatternTilePropsUBO { - std::array pattern_from; - std::array pattern_to; + /* 0 */ std::array pattern_from; + /* 16 */ std::array pattern_to; + /* 32 */ std::array texsize; + /* 40 */ float pad1; + /* 44 */ float pad2; + /* 48 */ }; -static_assert(sizeof(FillOutlinePatternTilePropsUBO) == 2 * 16); - -struct alignas(16) FillOutlinePatternInterpolateUBO { - float pattern_from_t; - float pattern_to_t; - float opacity_t; - float pad; -}; -static_assert(sizeof(FillOutlinePatternInterpolateUBO) == 1 * 16); +static_assert(sizeof(FillOutlinePatternTilePropsUBO) == 3 * 16); // // Fill outline triangulated struct alignas(16) FillOutlineTriangulatedDrawableUBO { - std::array matrix; - float ratio; - float pad1, pad2, pad3; + /* 0 */ std::array matrix; + /* 64 */ float ratio; + /* 68 */ float pad1; + /* 72 */ float pad2; + /* 76 */ float pad3; + /* 80 */ }; -static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) % 16 == 0); - -// -// Fill evaluated properties +static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) == 5 * 16); +/// Evaluated properties that do not depend on the tile struct alignas(16) FillEvaluatedPropsUBO { - Color color; - Color outline_color; - float opacity; - float fade; - float from_scale; - float to_scale; + /* 0 */ Color color; + /* 16 */ Color outline_color; + /* 32 */ float opacity; + /* 36 */ float fade; + /* 40 */ float from_scale; + /* 44 */ float to_scale; + /* 48 */ }; static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16); +#if MLN_UBO_CONSOLIDATION + +union FillDrawableUnionUBO { + FillDrawableUBO fillDrawableUBO; + FillOutlineDrawableUBO fillOutlineDrawableUBO; + FillPatternDrawableUBO fillPatternDrawableUBO; + FillOutlinePatternDrawableUBO fillOutlinePatternDrawableUBO; + FillOutlineTriangulatedDrawableUBO fillOutlineTriangulatedDrawableUBO; +}; + +union FillTilePropsUnionUBO { + FillPatternTilePropsUBO fillPatternTilePropsUBO; + FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO; +}; + +#endif + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/gl/drawable_background.hpp b/include/mbgl/shaders/gl/drawable_background.hpp index e7abe2b9300..9e7e233a1df 100644 --- a/include/mbgl/shaders/gl/drawable_background.hpp +++ b/include/mbgl/shaders/gl/drawable_background.hpp @@ -17,10 +17,12 @@ void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform BackgroundLayerUBO { + static constexpr const char* fragment = R"(layout (std140) uniform BackgroundPropsUBO { highp vec4 u_color; highp float u_opacity; - highp float layer_pad1, layer_pad2, layer_pad3; + lowp float props_pad1; + lowp float props_pad2; + lowp float props_pad3; }; void main() { diff --git a/include/mbgl/shaders/gl/drawable_background_pattern.hpp b/include/mbgl/shaders/gl/drawable_background_pattern.hpp index d8edc98c143..94cacec93d8 100644 --- a/include/mbgl/shaders/gl/drawable_background_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_background_pattern.hpp @@ -13,9 +13,12 @@ struct ShaderSource { static constexpr const char* name = "FillShader"; static constexpr const char* vertex = R"(layout (std140) uniform FillDrawableUBO { highp mat4 u_matrix; -}; -layout (std140) uniform FillInterpolateUBO { + // Interpolations highp float u_color_t; highp float u_opacity_t; - highp float interp_pad1, interp_pad2; + lowp float drawable_pad1; + lowp float drawable_pad2; }; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; @@ -51,12 +52,7 @@ lowp float opacity = u_opacity; gl_Position = u_matrix * vec4(a_pos, 0, 1); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform FillInterpolateUBO { - highp float u_color_t; - highp float u_opacity_t; - highp float interp_pad1, interp_pad2; -}; -layout (std140) uniform FillEvaluatedPropsUBO { + static constexpr const char* fragment = R"(layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; highp float u_opacity; diff --git a/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp b/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp index 76b83e8fc40..10a7d912fb9 100644 --- a/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_extrusion.hpp @@ -14,16 +14,31 @@ out vec4 v_color; layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; highp float u_tile_ratio; + // Interpolations + highp float u_base_t; + highp float u_height_t; + highp float u_color_t; + highp float u_pattern_from_t; + highp float u_pattern_to_t; + lowp float drawable_pad1; +}; + +layout (std140) uniform FillExtrusionTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; + layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; highp vec3 u_lightcolor; - highp float props_pad1; + lowp float props_pad1; highp vec3 u_lightpos; highp float u_base; highp float u_height; @@ -33,20 +48,9 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_fade; highp float u_from_scale; highp float u_to_scale; - highp float props_pad2; -}; -layout (std140) uniform FillExtrusionTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; -}; -layout (std140) uniform FillExtrusionInterpolateUBO { - highp float u_base_t; - highp float u_height_t; - highp float u_color_t; - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float interp_pad1, interp_pad2, interp_pad3; + lowp float props_pad2; }; + #ifndef HAS_UNIFORM_u_base layout (location = 2) in highp vec2 a_base; #endif diff --git a/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp b/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp index df273b63d75..11f7e40c42e 100644 --- a/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_extrusion_pattern.hpp @@ -23,21 +23,37 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; highp float u_tile_ratio; + // Interpolations + highp float u_base_t; + highp float u_height_t; + highp float u_color_t; + highp float u_pattern_from_t; + highp float u_pattern_to_t; + lowp float drawable_pad1; +}; + +layout (std140) uniform FillExtrusionTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; + layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; highp vec3 u_lightcolor; - highp float props_pad1; + lowp float props_pad1; highp vec3 u_lightpos; highp float u_base; highp float u_height; @@ -47,19 +63,7 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_fade; highp float u_from_scale; highp float u_to_scale; - highp float props_pad2; -}; -layout (std140) uniform FillExtrusionTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; -}; -layout (std140) uniform FillExtrusionInterpolateUBO { - highp float u_base_t; - highp float u_height_t; - highp float u_color_t; - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float interp_pad1, interp_pad2, interp_pad3; + lowp float props_pad2; }; #ifndef HAS_UNIFORM_u_base @@ -152,18 +156,18 @@ mediump vec4 pattern_to = u_pattern_to; in vec2 v_pos_b; in vec4 v_lighting; -layout (std140) uniform FillExtrusionDrawableUBO { - highp mat4 u_matrix; +layout (std140) uniform FillExtrusionTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; highp vec2 u_texsize; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_height_factor; - highp float u_tile_ratio; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; + layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; highp vec3 u_lightcolor; - highp float props_pad1; + lowp float props_pad1; highp vec3 u_lightpos; highp float u_base; highp float u_height; @@ -173,19 +177,7 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_fade; highp float u_from_scale; highp float u_to_scale; - highp float props_pad2; -}; -layout (std140) uniform FillExtrusionTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; -}; -layout (std140) uniform FillExtrusionInterpolateUBO { - highp float u_base_t; - highp float u_height_t; - highp float u_color_t; - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float interp_pad1, interp_pad2, interp_pad3; + lowp float props_pad2; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_fill_outline.hpp b/include/mbgl/shaders/gl/drawable_fill_outline.hpp index 08082a443a9..ae157ae5f4b 100644 --- a/include/mbgl/shaders/gl/drawable_fill_outline.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_outline.hpp @@ -16,17 +16,19 @@ struct ShaderSource { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; + layout (std140) uniform FillOutlineDrawableUBO { highp mat4 u_matrix; -}; -layout (std140) uniform FillOutlineInterpolateUBO { + // Interpolations highp float u_outline_color_t; highp float u_opacity_t; - highp float interp_pad1; - highp float interp_pad2; + lowp float drawable_pad1; + lowp float drawable_pad2; }; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; @@ -65,13 +67,7 @@ lowp float opacity = u_opacity; v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world_size; } )"; - static constexpr const char* fragment = R"(layout (std140) uniform FillOutlineInterpolateUBO { - highp float u_outline_color_t; - highp float u_opacity_t; - highp float interp_pad1; - highp float interp_pad2; -}; -layout (std140) uniform FillEvaluatedPropsUBO { + static constexpr const char* fragment = R"(layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; highp float u_opacity; diff --git a/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp b/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp index caaac380308..f197a56318f 100644 --- a/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_fill_outline_pattern.hpp @@ -16,26 +16,29 @@ struct ShaderSource { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; + layout (std140) uniform FillPatternDrawableUBO { highp mat4 u_matrix; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; - highp vec2 u_texsize; highp float u_tile_ratio; - highp float drawable_pad1; + // Interpolations + highp float u_pattern_from_t; + highp float u_pattern_to_t; + highp float u_opacity_t; }; + layout (std140) uniform FillPatternTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; -layout (std140) uniform FillPatternInterpolateUBO { - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float u_opacity_t; - highp float interp_pad1; -}; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; @@ -98,24 +101,14 @@ mediump vec4 pattern_to = u_pattern_to; v_pos_b = get_pattern_pos(u_pixel_coord_upper, u_pixel_coord_lower, toScale * display_size_b, tileZoomRatio, a_pos); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform FillPatternDrawableUBO { - highp mat4 u_matrix; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp vec2 u_texsize; - highp float u_tile_ratio; - highp float drawable_pad1; -}; -layout (std140) uniform FillPatternTilePropsUBO { + static constexpr const char* fragment = R"(layout (std140) uniform FillPatternTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; -layout (std140) uniform FillPatternInterpolateUBO { - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float u_opacity_t; - highp float interp_pad1; -}; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/include/mbgl/shaders/gl/drawable_heatmap.hpp b/include/mbgl/shaders/gl/drawable_heatmap.hpp index ebec009db5d..9b93c798e12 100644 --- a/include/mbgl/shaders/gl/drawable_heatmap.hpp +++ b/include/mbgl/shaders/gl/drawable_heatmap.hpp @@ -14,8 +14,10 @@ out vec2 v_extrude; layout (std140) uniform HeatmapDrawableUBO { highp mat4 u_matrix; highp float u_extrude_scale; + // Interpolations + lowp float u_weight_t; + lowp float u_radius_t; lowp float drawable_pad1; - lowp vec2 drawable_pad2; }; layout (std140) uniform HeatmapEvaluatedPropsUBO { @@ -25,12 +27,6 @@ layout (std140) uniform HeatmapEvaluatedPropsUBO { lowp float props_pad1; }; -layout (std140) uniform HeatmapInterpolateUBO { - lowp float u_weight_t; - lowp float u_radius_t; - lowp vec2 interp_pad1; -}; - #ifndef HAS_UNIFORM_u_weight layout (location = 1) in highp vec2 a_weight; out highp float weight; diff --git a/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp b/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp index c1593d0059f..19317a2d6c6 100644 --- a/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp +++ b/include/mbgl/shaders/gl/drawable_heatmap_texture.hpp @@ -19,12 +19,16 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; + layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; highp float u_opacity; - lowp float props_pad1, props_pad2, props_pad3; + lowp float props_pad1; + lowp float props_pad2; + lowp float props_pad3; }; void main() { @@ -41,7 +45,9 @@ uniform sampler2D u_color_ramp; layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; highp float u_opacity; - lowp float props_pad1, props_pad2, props_pad3; + lowp float props_pad1; + lowp float props_pad2; + lowp float props_pad3; }; void main() { diff --git a/include/mbgl/shaders/gl/drawable_hillshade.hpp b/include/mbgl/shaders/gl/drawable_hillshade.hpp index 3d706de1a5f..8d186538040 100644 --- a/include/mbgl/shaders/gl/drawable_hillshade.hpp +++ b/include/mbgl/shaders/gl/drawable_hillshade.hpp @@ -13,8 +13,6 @@ layout (location = 1) in vec2 a_texture_pos; layout (std140) uniform HillshadeDrawableUBO { highp mat4 u_matrix; - highp vec2 u_latrange; - highp vec2 u_light; }; out vec2 v_pos; @@ -27,8 +25,7 @@ void main() { static constexpr const char* fragment = R"(in vec2 v_pos; uniform sampler2D u_image; -layout (std140) uniform HillshadeDrawableUBO { - highp mat4 u_matrix; +layout (std140) uniform HillshadeTilePropsUBO { highp vec2 u_latrange; highp vec2 u_light; }; diff --git a/include/mbgl/shaders/gl/drawable_hillshade_prepare.hpp b/include/mbgl/shaders/gl/drawable_hillshade_prepare.hpp index 76335aed366..2a2bf01b533 100644 --- a/include/mbgl/shaders/gl/drawable_hillshade_prepare.hpp +++ b/include/mbgl/shaders/gl/drawable_hillshade_prepare.hpp @@ -13,6 +13,9 @@ layout (location = 1) in vec2 a_texture_pos; layout (std140) uniform HillshadePrepareDrawableUBO { highp mat4 u_matrix; +}; + +layout (std140) uniform HillshadePrepareTilePropsUBO { highp vec4 u_unpack; highp vec2 u_dimension; highp float u_zoom; @@ -36,8 +39,7 @@ precision highp float; in vec2 v_pos; uniform sampler2D u_image; -layout (std140) uniform HillshadePrepareDrawableUBO { - highp mat4 u_matrix; +layout (std140) uniform HillshadePrepareTilePropsUBO { highp vec4 u_unpack; highp vec2 u_dimension; highp float u_zoom; diff --git a/include/mbgl/shaders/gl/drawable_line.hpp b/include/mbgl/shaders/gl/drawable_line.hpp index ac8a9cabfb9..1f093581782 100644 --- a/include/mbgl/shaders/gl/drawable_line.hpp +++ b/include/mbgl/shaders/gl/drawable_line.hpp @@ -27,23 +27,21 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform LineDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineInterpolationUBO { + // Interpolations lowp float u_color_t; lowp float u_blur_t; lowp float u_opacity_t; lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; - highp vec2 interp_pad1; + lowp float drawable_pad1; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -54,8 +52,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; out vec2 v_normal; @@ -167,23 +165,7 @@ mediump float width = u_width; v_width2 = vec2(outset, inset); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform LineDrawableUBO { - highp mat4 u_matrix; - mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineInterpolationUBO { - lowp float u_color_t; - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_gapwidth_t; - lowp float u_offset_t; - lowp float u_width_t; - highp vec2 interp_pad1; -}; - -layout (std140) uniform LineEvaluatedPropsUBO { + static constexpr const char* fragment = R"(layout (std140) uniform LineEvaluatedPropsUBO { highp vec4 u_color; lowp float u_blur; lowp float u_opacity; @@ -191,8 +173,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; in vec2 v_width2; diff --git a/include/mbgl/shaders/gl/drawable_line_gradient.hpp b/include/mbgl/shaders/gl/drawable_line_gradient.hpp index 0ddae503a60..c77e020c44a 100644 --- a/include/mbgl/shaders/gl/drawable_line_gradient.hpp +++ b/include/mbgl/shaders/gl/drawable_line_gradient.hpp @@ -31,23 +31,21 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform LineGradientDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineGradientInterpolationUBO { + // Interpolations lowp float u_blur_t; lowp float u_opacity_t; lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; - highp float interp_pad1; - highp vec2 interp_pad2; + lowp float drawable_pad1; + lowp float drawable_pad2; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -58,8 +56,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; out vec2 v_normal; @@ -162,23 +160,7 @@ mediump float width = u_width; v_width2 = vec2(outset, inset); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform LineGradientDrawableUBO { - highp mat4 u_matrix; - mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineGradientInterpolationUBO { - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_gapwidth_t; - lowp float u_offset_t; - lowp float u_width_t; - highp float interp_pad1; - highp vec2 interp_pad2; -}; - -layout (std140) uniform LineEvaluatedPropsUBO { + static constexpr const char* fragment = R"(layout (std140) uniform LineEvaluatedPropsUBO { highp vec4 u_color; lowp float u_blur; lowp float u_opacity; @@ -186,8 +168,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_line_pattern.hpp b/include/mbgl/shaders/gl/drawable_line_pattern.hpp index cc03b8ffce4..ea4b8809f80 100644 --- a/include/mbgl/shaders/gl/drawable_line_pattern.hpp +++ b/include/mbgl/shaders/gl/drawable_line_pattern.hpp @@ -31,18 +31,13 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; - layout (std140) uniform LinePatternDrawableUBO { highp mat4 u_matrix; - mediump vec4 u_scale; - highp vec2 u_texsize; mediump float u_ratio; - highp float u_fade; -}; - -layout (std140) uniform LinePatternInterpolationUBO { + // Interpolations lowp float u_blur_t; lowp float u_opacity_t; lowp float u_offset_t; @@ -50,12 +45,15 @@ layout (std140) uniform LinePatternInterpolationUBO { lowp float u_width_t; lowp float u_pattern_from_t; lowp float u_pattern_to_t; - highp float interp_pad1; }; -layout (std140) uniform LinePatternTilePropertiesUBO { +layout (std140) uniform LinePatternTilePropsUBO { lowp vec4 u_pattern_from; lowp vec4 u_pattern_to; + mediump vec4 u_scale; + highp vec2 u_texsize; + highp float u_fade; + lowp float tileprops_pad1; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -66,8 +64,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; out vec2 v_normal; @@ -188,28 +186,13 @@ mediump vec4 pattern_to = u_pattern_to; v_width2 = vec2(outset, inset); } )"; - static constexpr const char* fragment = R"(layout (std140) uniform LinePatternDrawableUBO { - highp mat4 u_matrix; + static constexpr const char* fragment = R"(layout (std140) uniform LinePatternTilePropsUBO { + lowp vec4 u_pattern_from; + lowp vec4 u_pattern_to; mediump vec4 u_scale; highp vec2 u_texsize; - mediump float u_ratio; highp float u_fade; -}; - -layout (std140) uniform LinePatternInterpolationUBO { - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_offset_t; - lowp float u_gapwidth_t; - lowp float u_width_t; - lowp float u_pattern_from_t; - lowp float u_pattern_to_t; - highp float interp_pad1; -}; - -layout (std140) uniform LinePatternTilePropertiesUBO { - lowp vec4 u_pattern_from; - lowp vec4 u_pattern_to; + lowp float tileprops_pad1; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -220,8 +203,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_line_sdf.hpp b/include/mbgl/shaders/gl/drawable_line_sdf.hpp index 7fef18b0780..7772658f2c2 100644 --- a/include/mbgl/shaders/gl/drawable_line_sdf.hpp +++ b/include/mbgl/shaders/gl/drawable_line_sdf.hpp @@ -31,22 +31,18 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform LineSDFDrawableUBO { highp mat4 u_matrix; highp vec2 u_patternscale_a; highp vec2 u_patternscale_b; - mediump float u_ratio; highp float u_tex_y_a; highp float u_tex_y_b; - highp float u_sdfgamma; - highp float u_mix; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineSDFInterpolationUBO { + mediump float u_ratio; + // Interpolations lowp float u_color_t; lowp float u_blur_t; lowp float u_opacity_t; @@ -54,7 +50,8 @@ layout (std140) uniform LineSDFInterpolationUBO { lowp float u_offset_t; lowp float u_width_t; lowp float u_floorwidth_t; - highp float interp_pad1; + lowp float drawable_pad1; + lowp float drawable_pad2; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -65,8 +62,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; out vec2 v_normal; @@ -191,28 +188,11 @@ lowp float floorwidth = u_floorwidth; v_width2 = vec2(outset, inset); } )"; - static constexpr const char* fragment = R"( -layout (std140) uniform LineSDFDrawableUBO { - highp mat4 u_matrix; - highp vec2 u_patternscale_a; - highp vec2 u_patternscale_b; - mediump float u_ratio; - highp float u_tex_y_a; - highp float u_tex_y_b; + static constexpr const char* fragment = R"(layout (std140) uniform LineSDFTilePropsUBO { highp float u_sdfgamma; highp float u_mix; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineSDFInterpolationUBO { - lowp float u_color_t; - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_gapwidth_t; - lowp float u_offset_t; - lowp float u_width_t; - lowp float u_floorwidth_t; - highp float interp_pad1; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -223,8 +203,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; uniform sampler2D u_image; diff --git a/include/mbgl/shaders/gl/drawable_location_indicator.hpp b/include/mbgl/shaders/gl/drawable_location_indicator.hpp new file mode 100644 index 00000000000..af1c0d5c465 --- /dev/null +++ b/include/mbgl/shaders/gl/drawable_location_indicator.hpp @@ -0,0 +1,16 @@ +// Generated code, do not modify this file! +#pragma once +#include + +namespace mbgl { +namespace shaders { + +template <> +struct ShaderSource { + static constexpr const char* name = "LocationIndicatorShader"; + static constexpr const char* vertex = R"()"; + static constexpr const char* fragment = R"()"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp b/include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp new file mode 100644 index 00000000000..cc26f8711af --- /dev/null +++ b/include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp @@ -0,0 +1,16 @@ +// Generated code, do not modify this file! +#pragma once +#include + +namespace mbgl { +namespace shaders { + +template <> +struct ShaderSource { + static constexpr const char* name = "LocationIndicatorTexturedShader"; + static constexpr const char* vertex = R"()"; + static constexpr const char* fragment = R"()"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/gl/drawable_raster.hpp b/include/mbgl/shaders/gl/drawable_raster.hpp index 36eea70f8d9..ee2865764d1 100644 --- a/include/mbgl/shaders/gl/drawable_raster.hpp +++ b/include/mbgl/shaders/gl/drawable_raster.hpp @@ -22,8 +22,8 @@ layout (std140) uniform RasterEvaluatedPropsUBO { highp float u_brightness_high; highp float u_saturation_factor; highp float u_contrast_factor; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; layout (location = 0) in vec2 a_pos; @@ -54,8 +54,8 @@ void main() { highp float u_brightness_high; highp float u_saturation_factor; highp float u_contrast_factor; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; uniform sampler2D u_image0; uniform sampler2D u_image1; diff --git a/include/mbgl/shaders/gl/drawable_symbol_icon.hpp b/include/mbgl/shaders/gl/drawable_symbol_icon.hpp index ecc372e8a15..9ac73b34aa4 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_icon.hpp @@ -22,7 +22,8 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform SymbolDrawableUBO { @@ -33,29 +34,21 @@ layout (std140) uniform SymbolDrawableUBO { highp vec2 u_texsize; highp vec2 u_texsize_icon; - highp float u_gamma_scale; + bool u_is_text_prop; bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - -layout (std140) uniform SymbolTilePropsUBO { - bool u_is_text; - bool u_is_halo; bool u_pitch_with_map; bool u_is_size_zoom_constant; bool u_is_size_feature_constant; + highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; -}; -layout (std140) uniform SymbolInterpolateUBO { + // Interpolations highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float interp_pad1, interp_pad2, interp_pad3; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -64,13 +57,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; out vec2 v_tex; @@ -82,7 +75,7 @@ out lowp float opacity; #endif void main() { - highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity; #ifndef HAS_UNIFORM_u_opacity opacity = unpack_mix_vec2(a_opacity, u_opacity_t); @@ -124,7 +117,7 @@ lowp float opacity = u_opacity; size *= perspective_ratio; - float fontScale = u_is_text ? size / 24.0 : size; + float fontScale = u_is_text_prop ? size / 24.0 : size; highp float symbol_rotation = 0.0; if (u_rotate_symbol) { @@ -155,12 +148,8 @@ lowp float opacity = u_opacity; layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; - bool u_pitch_with_map; - bool u_is_size_zoom_constant; - bool u_is_size_feature_constant; - highp float u_size_t; // used to interpolate between zoom stops when size is a composite function - highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; + highp float u_gamma_scale; + lowp float tileprops_pad1; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -169,13 +158,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; in vec2 v_tex; diff --git a/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp b/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp index 4b75ae40823..12d88136a7c 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp @@ -30,7 +30,8 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform SymbolDrawableUBO { @@ -41,29 +42,21 @@ layout (std140) uniform SymbolDrawableUBO { highp vec2 u_texsize; highp vec2 u_texsize_icon; - highp float u_gamma_scale; + bool u_is_text_prop; bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - -layout (std140) uniform SymbolTilePropsUBO { - bool u_is_text; - bool u_is_halo; bool u_pitch_with_map; bool u_is_size_zoom_constant; bool u_is_size_feature_constant; + highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; -}; -layout (std140) uniform SymbolInterpolateUBO { + // Interpolations highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float interp_pad1, interp_pad2, interp_pad3; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -72,13 +65,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; out vec2 v_data0; @@ -106,11 +99,11 @@ out lowp float halo_blur; #endif void main() { - highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; - highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; - highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; - highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; - highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + highp vec4 u_fill_color = u_is_text_prop ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text_prop ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text_prop ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text_prop ? u_text_halo_blur : u_icon_halo_blur; #ifndef HAS_UNIFORM_u_fill_color fill_color = unpack_mix_color(a_fill_color, u_fill_color_t); @@ -176,7 +169,7 @@ lowp float halo_blur = u_halo_blur; size *= perspective_ratio; - float fontScale = u_is_text ? size / 24.0 : size; + float fontScale = u_is_text_prop ? size / 24.0 : size; highp float symbol_rotation = 0.0; if (u_rotate_symbol) { @@ -209,28 +202,11 @@ lowp float halo_blur = u_halo_blur; )"; static constexpr const char* fragment = R"(#define SDF_PX 8.0 -layout (std140) uniform SymbolDrawableUBO { - highp mat4 u_matrix; - highp mat4 u_label_plane_matrix; - highp mat4 u_coord_matrix; - - highp vec2 u_texsize; - highp vec2 u_texsize_icon; - - highp float u_gamma_scale; - bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; - bool u_pitch_with_map; - bool u_is_size_zoom_constant; - bool u_is_size_feature_constant; - highp float u_size_t; // used to interpolate between zoom stops when size is a composite function - highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; + highp float u_gamma_scale; + lowp float tileprops_pad1; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -239,13 +215,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; uniform sampler2D u_texture; diff --git a/include/mbgl/shaders/gl/drawable_symbol_sdf_text.hpp b/include/mbgl/shaders/gl/drawable_symbol_sdf_text.hpp deleted file mode 100644 index 7dbcfb10f69..00000000000 --- a/include/mbgl/shaders/gl/drawable_symbol_sdf_text.hpp +++ /dev/null @@ -1,323 +0,0 @@ -// Generated code, do not modify this file! -#pragma once -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr const char* name = "SymbolSDFTextShader"; - static constexpr const char* vertex = R"(layout (location = 0) in vec4 a_pos_offset; -layout (location = 1) in vec4 a_data; -layout (location = 2) in vec4 a_pixeloffset; -layout (location = 3) in vec3 a_projected_pos; -layout (location = 4) in float a_fade_opacity; - -// contents of a_size vary based on the type of property value -// used for {text,icon}-size. -// For constants, a_size is disabled. -// For source functions, we bind only one value per vertex: the value of {text,icon}-size evaluated for the current feature. -// For composite functions: -// [ text-size(lowerZoomStop, feature), -// text-size(upperZoomStop, feature) ] - -layout (std140) uniform SymbolDrawableUBO { - highp mat4 u_matrix; - highp mat4 u_label_plane_matrix; - highp mat4 u_coord_matrix; - - highp vec2 u_texsize; - highp vec2 u_texsize_icon; - - highp float u_gamma_scale; - highp float u_device_pixel_ratio; - - highp float u_camera_to_center_distance; - highp float u_pitch; - bool u_rotate_symbol; - highp float u_aspect_ratio; - highp vec2 u_pad1; -}; - -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_pad7; - highp vec2 u_pad8; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { - bool u_is_text; - bool u_is_halo; - bool u_pitch_with_map; - bool u_is_size_zoom_constant; - bool u_is_size_feature_constant; - highp float u_size_t; // used to interpolate between zoom stops when size is a composite function - highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; -}; - -layout (std140) uniform SymbolDrawableInterpolateUBO { - highp float u_fill_color_t; - highp float u_halo_color_t; - highp float u_opacity_t; - highp float u_halo_width_t; - highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; -}; - -out vec2 v_data0; -out vec3 v_data1; - -#ifndef HAS_UNIFORM_u_fill_color -layout (location = 5) in highp vec4 a_fill_color; -out highp vec4 fill_color; -#endif -#ifndef HAS_UNIFORM_u_halo_color -layout (location = 6) in highp vec4 a_halo_color; -out highp vec4 halo_color; -#endif -#ifndef HAS_UNIFORM_u_opacity -layout (location = 7) in lowp vec2 a_opacity; -out lowp float opacity; -#endif -#ifndef HAS_UNIFORM_u_halo_width -layout (location = 8) in lowp vec2 a_halo_width; -out lowp float halo_width; -#endif -#ifndef HAS_UNIFORM_u_halo_blur -layout (location = 9) in lowp vec2 a_halo_blur; -out lowp float halo_blur; -#endif - -void main() { - #ifndef HAS_UNIFORM_u_fill_color -fill_color = unpack_mix_color(a_fill_color, u_fill_color_t); -#else -highp vec4 fill_color = u_fill_color; -#endif - #ifndef HAS_UNIFORM_u_halo_color -halo_color = unpack_mix_color(a_halo_color, u_halo_color_t); -#else -highp vec4 halo_color = u_halo_color; -#endif - #ifndef HAS_UNIFORM_u_opacity -opacity = unpack_mix_vec2(a_opacity, u_opacity_t); -#else -lowp float opacity = u_opacity; -#endif - #ifndef HAS_UNIFORM_u_halo_width -halo_width = unpack_mix_vec2(a_halo_width, u_halo_width_t); -#else -lowp float halo_width = u_halo_width; -#endif - #ifndef HAS_UNIFORM_u_halo_blur -halo_blur = unpack_mix_vec2(a_halo_blur, u_halo_blur_t); -#else -lowp float halo_blur = u_halo_blur; -#endif - - vec2 a_pos = a_pos_offset.xy; - vec2 a_offset = a_pos_offset.zw; - - vec2 a_tex = a_data.xy; - vec2 a_size = a_data.zw; - - float a_size_min = floor(a_size[0] * 0.5); - vec2 a_pxoffset = a_pixeloffset.xy; - - highp float segment_angle = -a_projected_pos[2]; - float size; - - if (!u_is_size_zoom_constant && !u_is_size_feature_constant) { - size = mix(a_size_min, a_size[1], u_size_t) / 128.0; - } else if (u_is_size_zoom_constant && !u_is_size_feature_constant) { - size = a_size_min / 128.0; - } else { - size = u_size; - } - - vec4 projectedPoint = u_matrix * vec4(a_pos, 0, 1); - highp float camera_to_anchor_distance = projectedPoint.w; - // If the label is pitched with the map, layout is done in pitched space, - // which makes labels in the distance smaller relative to viewport space. - // We counteract part of that effect by multiplying by the perspective ratio. - // If the label isn't pitched with the map, we do layout in viewport space, - // which makes labels in the distance larger relative to the features around - // them. We counteract part of that effect by dividing by the perspective ratio. - highp float distance_ratio = u_pitch_with_map ? - camera_to_anchor_distance / u_camera_to_center_distance : - u_camera_to_center_distance / camera_to_anchor_distance; - highp float perspective_ratio = clamp( - 0.5 + 0.5 * distance_ratio, - 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles - 4.0); - - size *= perspective_ratio; - - float fontScale = u_is_text ? size / 24.0 : size; - - highp float symbol_rotation = 0.0; - if (u_rotate_symbol) { - // Point labels with 'rotation-alignment: map' are horizontal with respect to tile units - // To figure out that angle in projected space, we draw a short horizontal line in tile - // space, project it, and measure its angle in projected space. - vec4 offsetProjectedPoint = u_matrix * vec4(a_pos + vec2(1, 0), 0, 1); - - vec2 a = projectedPoint.xy / projectedPoint.w; - vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; - - symbol_rotation = atan((b.y - a.y) / u_aspect_ratio, b.x - a.x); - } - - highp float angle_sin = sin(segment_angle + symbol_rotation); - highp float angle_cos = cos(segment_angle + symbol_rotation); - mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos); - - vec4 projected_pos = u_label_plane_matrix * vec4(a_projected_pos.xy, 0.0, 1.0); - gl_Position = u_coord_matrix * vec4(projected_pos.xy / projected_pos.w + rotation_matrix * (a_offset / 32.0 * fontScale + a_pxoffset), 0.0, 1.0); - float gamma_scale = gl_Position.w; - - vec2 fade_opacity = unpack_opacity(a_fade_opacity); - float fade_change = fade_opacity[1] > 0.5 ? u_fade_change : -u_fade_change; - float interpolated_fade_opacity = max(0.0, min(1.0, fade_opacity[0] + fade_change)); - - v_data0 = a_tex / u_texsize; - v_data1 = vec3(gamma_scale, size, interpolated_fade_opacity); -} -)"; - static constexpr const char* fragment = R"(#define SDF_PX 8.0 - -layout (std140) uniform SymbolDrawableUBO { - highp mat4 u_matrix; - highp mat4 u_label_plane_matrix; - highp mat4 u_coord_matrix; - - highp vec2 u_texsize; - highp vec2 u_texsize_icon; - - highp float u_gamma_scale; - highp float u_device_pixel_ratio; - - highp float u_camera_to_center_distance; - highp float u_pitch; - bool u_rotate_symbol; - highp float u_aspect_ratio; - highp vec2 u_pad1; -}; - -layout (std140) uniform SymbolDynamicUBO { - highp float u_fade_change; - highp float u_pad7; - highp vec2 u_pad8; -}; - -layout (std140) uniform SymbolDrawablePaintUBO { - highp vec4 u_fill_color; - highp vec4 u_halo_color; - highp float u_opacity; - highp float u_halo_width; - highp float u_halo_blur; - highp float u_padding; -}; - -layout (std140) uniform SymbolDrawableTilePropsUBO { - bool u_is_text; - bool u_is_halo; - bool u_pitch_with_map; - bool u_is_size_zoom_constant; - bool u_is_size_feature_constant; - highp float u_size_t; // used to interpolate between zoom stops when size is a composite function - highp float u_size; // used when size is both zoom and feature constant - bool u_pad3; -}; - -layout (std140) uniform SymbolDrawableInterpolateUBO { - highp float u_fill_color_t; - highp float u_halo_color_t; - highp float u_opacity_t; - highp float u_halo_width_t; - highp float u_halo_blur_t; - highp float u_pad4,u_pad5,u_pad6; -}; - -uniform sampler2D u_texture; - -in vec2 v_data0; -in vec3 v_data1; - -#ifndef HAS_UNIFORM_u_fill_color -in highp vec4 fill_color; -#endif -#ifndef HAS_UNIFORM_u_halo_color -in highp vec4 halo_color; -#endif -#ifndef HAS_UNIFORM_u_opacity -in lowp float opacity; -#endif -#ifndef HAS_UNIFORM_u_halo_width -in lowp float halo_width; -#endif -#ifndef HAS_UNIFORM_u_halo_blur -in lowp float halo_blur; -#endif - -void main() { - #ifdef HAS_UNIFORM_u_fill_color -highp vec4 fill_color = u_fill_color; -#endif - #ifdef HAS_UNIFORM_u_halo_color -highp vec4 halo_color = u_halo_color; -#endif - #ifdef HAS_UNIFORM_u_opacity -lowp float opacity = u_opacity; -#endif - #ifdef HAS_UNIFORM_u_halo_width -lowp float halo_width = u_halo_width; -#endif - #ifdef HAS_UNIFORM_u_halo_blur -lowp float halo_blur = u_halo_blur; -#endif - - float EDGE_GAMMA = 0.105 / u_device_pixel_ratio; - - vec2 tex = v_data0.xy; - float gamma_scale = v_data1.x; - float size = v_data1.y; - float fade_opacity = v_data1[2]; - - float fontScale = u_is_text ? size / 24.0 : size; - - lowp vec4 color = fill_color; - highp float gamma = EDGE_GAMMA / (fontScale * u_gamma_scale); - lowp float buff = (256.0 - 64.0) / 256.0; - if (u_is_halo) { - color = halo_color; - gamma = (halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (fontScale * u_gamma_scale); - buff = (6.0 - halo_width / fontScale) / SDF_PX; - } - - lowp float dist = texture(u_texture, tex).a; - highp float gamma_scaled = gamma * gamma_scale; - highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); - - fragColor = color * (alpha * opacity * fade_opacity); - -#ifdef OVERDRAW_INSPECTOR - fragColor = vec4(1.0); -#endif -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp b/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp index 8f47d12c073..4b55116f129 100644 --- a/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp +++ b/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp @@ -29,7 +29,8 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform SymbolDrawableUBO { @@ -40,29 +41,21 @@ layout (std140) uniform SymbolDrawableUBO { highp vec2 u_texsize; highp vec2 u_texsize_icon; - highp float u_gamma_scale; + bool u_is_text_prop; bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - -layout (std140) uniform SymbolTilePropsUBO { - bool u_is_text; - bool u_is_halo; bool u_pitch_with_map; bool u_is_size_zoom_constant; bool u_is_size_feature_constant; + highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; -}; -layout (std140) uniform SymbolInterpolateUBO { + // Interpolations highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float interp_pad1, interp_pad2, interp_pad3; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -71,13 +64,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; out vec4 v_data0; @@ -105,11 +98,11 @@ out lowp float halo_blur; #endif void main() { - highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; - highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; - highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; - highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; - highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + highp vec4 u_fill_color = u_is_text_prop ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text_prop ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text_prop ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text_prop ? u_text_halo_blur : u_icon_halo_blur; #ifndef HAS_UNIFORM_u_fill_color fill_color = unpack_mix_color(a_fill_color, u_fill_color_t); @@ -212,28 +205,11 @@ lowp float halo_blur = u_halo_blur; #define SDF 1.0 #define ICON 0.0 -layout (std140) uniform SymbolDrawableUBO { - highp mat4 u_matrix; - highp mat4 u_label_plane_matrix; - highp mat4 u_coord_matrix; - - highp vec2 u_texsize; - highp vec2 u_texsize_icon; - - highp float u_gamma_scale; - bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; - bool u_pitch_with_map; - bool u_is_size_zoom_constant; - bool u_is_size_feature_constant; - highp float u_size_t; // used to interpolate between zoom stops when size is a composite function - highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; + highp float u_gamma_scale; + lowp float tileprops_pad1; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -242,13 +218,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; uniform sampler2D u_texture; diff --git a/include/mbgl/shaders/heatmap_layer_ubo.hpp b/include/mbgl/shaders/heatmap_layer_ubo.hpp index 68ac43ea8c9..16a3704fe16 100644 --- a/include/mbgl/shaders/heatmap_layer_ubo.hpp +++ b/include/mbgl/shaders/heatmap_layer_ubo.hpp @@ -6,26 +6,26 @@ namespace mbgl { namespace shaders { struct alignas(16) HeatmapDrawableUBO { - std::array matrix; - float extrude_scale; - std::array padding; -}; -static_assert(sizeof(HeatmapDrawableUBO) % 16 == 0); + /* 0 */ std::array matrix; + /* 64 */ float extrude_scale; -struct alignas(16) HeatmapEvaluatedPropsUBO { - float weight; - float radius; - float intensity; - float padding; + // Interpolations + /* 68 */ float weight_t; + /* 72 */ float radius_t; + /* 76 */ float pad1; + /* 80 */ }; -static_assert(sizeof(HeatmapEvaluatedPropsUBO) % 16 == 0); +static_assert(sizeof(HeatmapDrawableUBO) == 5 * 16); -struct alignas(16) HeatmapInterpolateUBO { - float weight_t; - float radius_t; - std::array padding; +/// Evaluated properties that do not depend on the tile +struct alignas(16) HeatmapEvaluatedPropsUBO { + /* 0 */ float weight; + /* 4 */ float radius; + /* 8 */ float intensity; + /* 12 */ float padding; + /* 16 */ }; -static_assert(sizeof(HeatmapInterpolateUBO) % 16 == 0); +static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp b/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp index a4888dbcf0e..e94351e06f0 100644 --- a/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp +++ b/include/mbgl/shaders/heatmap_texture_layer_ubo.hpp @@ -6,11 +6,14 @@ namespace mbgl { namespace shaders { struct alignas(16) HeatmapTexturePropsUBO { - std::array matrix; - float opacity; - float pad1, pad2, pad3; + /* 0 */ std::array matrix; + /* 64 */ float opacity; + /* 68 */ float pad1; + /* 72 */ float pad2; + /* 76 */ float pad3; + /* 80 */ }; -static_assert(sizeof(HeatmapTexturePropsUBO) % 16 == 0); +static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/hillshade_layer_ubo.hpp b/include/mbgl/shaders/hillshade_layer_ubo.hpp index 77fd1a993ee..7edee8f7729 100644 --- a/include/mbgl/shaders/hillshade_layer_ubo.hpp +++ b/include/mbgl/shaders/hillshade_layer_ubo.hpp @@ -6,18 +6,26 @@ namespace mbgl { namespace shaders { struct alignas(16) HillshadeDrawableUBO { - std::array matrix; - std::array latrange; - std::array light; + /* 0 */ std::array matrix; + /* 64 */ }; -static_assert(sizeof(HillshadeDrawableUBO) == 16 * 5); +static_assert(sizeof(HillshadeDrawableUBO) == 4 * 16); +struct alignas(16) HillshadeTilePropsUBO { + /* 0 */ std::array latrange; + /* 8 */ std::array light; + /* 16 */ +}; +static_assert(sizeof(HillshadeTilePropsUBO) == 16); + +/// Evaluated properties that do not depend on the tile struct alignas(16) HillshadeEvaluatedPropsUBO { - Color highlight; - Color shadow; - Color accent; + /* 0 */ Color highlight; + /* 16 */ Color shadow; + /* 32 */ Color accent; + /* 48 */ }; -static_assert(sizeof(HillshadeEvaluatedPropsUBO) % 16 == 0); +static_assert(sizeof(HillshadeEvaluatedPropsUBO) == 3 * 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp b/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp index 57ac65f3e97..a00cdc6e7c0 100644 --- a/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp +++ b/include/mbgl/shaders/hillshade_prepare_layer_ubo.hpp @@ -6,13 +6,19 @@ namespace mbgl { namespace shaders { struct alignas(16) HillshadePrepareDrawableUBO { - std::array matrix; - std::array unpack; - std::array dimension; - float zoom; - float maxzoom; + /* 0 */ std::array matrix; + /* 64 */ }; -static_assert(sizeof(HillshadePrepareDrawableUBO) % 16 == 0); +static_assert(sizeof(HillshadePrepareDrawableUBO) == 4 * 16); + +struct alignas(16) HillshadePrepareTilePropsUBO { + /* 0 */ std::array unpack; + /* 16 */ std::array dimension; + /* 24 */ float zoom; + /* 28 */ float maxzoom; + /* 32 */ +}; +static_assert(sizeof(HillshadePrepareTilePropsUBO) == 2 * 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/layer_ubo.hpp b/include/mbgl/shaders/layer_ubo.hpp index d46d16104b6..a1704d533ec 100644 --- a/include/mbgl/shaders/layer_ubo.hpp +++ b/include/mbgl/shaders/layer_ubo.hpp @@ -37,25 +37,39 @@ static_assert(sizeof(Attribute) == 8); // Global UBOs struct alignas(16) GlobalPaintParamsUBO { - std::array pattern_atlas_texsize; - std::array units_to_pixels; - std::array world_size; - float camera_to_center_distance; - float symbol_fade_change; - float aspect_ratio; - float pixel_ratio; - float zoom; - float pad1; + /* 0 */ std::array pattern_atlas_texsize; + /* 8 */ std::array units_to_pixels; + /* 16 */ std::array world_size; + /* 24 */ float camera_to_center_distance; + /* 28 */ float symbol_fade_change; + /* 32 */ float aspect_ratio; + /* 36 */ float pixel_ratio; + /* 40 */ float map_zoom; + /* 44 */ float pad1; + /* 48 */ }; static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16); +#if MLN_RENDER_BACKEND_VULKAN +struct alignas(16) GlobalPlatformParamsUBO { + /* 0 */ alignas(16) std::array rotation0; + /* 16 */ alignas(16) std::array rotation1; + /* 32 */ +}; +static_assert(sizeof(GlobalPlatformParamsUBO) == 2 * 16); +#endif + enum { idGlobalPaintParamsUBO, -#if MLN_RENDER_BACKEND_VULKAN - PlatformParamsUBO, +#if MLN_RENDER_BACKEND_METAL + idGlobalUBOIndex, +#elif MLN_RENDER_BACKEND_VULKAN + idGlobalPlatformParamsUBO, #endif - globalUBOCount + globalUBOCount, }; +#define MLN_UBO_CONSOLIDATION MLN_RENDER_BACKEND_METAL + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/line_layer_ubo.hpp b/include/mbgl/shaders/line_layer_ubo.hpp index 82b22842ad5..f685be9059d 100644 --- a/include/mbgl/shaders/line_layer_ubo.hpp +++ b/include/mbgl/shaders/line_layer_ubo.hpp @@ -11,6 +11,109 @@ namespace mbgl { namespace shaders { +// +// Line + +struct alignas(16) LineDrawableUBO { + /* 0 */ std::array matrix; + /* 64 */ float ratio; + + // Interpolations + /* 68 */ float color_t; + /* 72 */ float blur_t; + /* 76 */ float opacity_t; + /* 80 */ float gapwidth_t; + /* 84 */ float offset_t; + /* 88 */ float width_t; + /* 92 */ float pad1; + /* 96 */ +}; +static_assert(sizeof(LineDrawableUBO) == 6 * 16); + +// +// Line gradient + +struct alignas(16) LineGradientDrawableUBO { + /* 0 */ std::array matrix; + /* 64 */ float ratio; + + // Interpolations + /* 68 */ float blur_t; + /* 72 */ float opacity_t; + /* 76 */ float gapwidth_t; + /* 80 */ float offset_t; + /* 84 */ float width_t; + /* 88 */ float pad1; + /* 92 */ float pad2; + /* 96 */ +}; +static_assert(sizeof(LineGradientDrawableUBO) == 6 * 16); + +// +// Line pattern + +struct alignas(16) LinePatternDrawableUBO { + /* 0 */ std::array matrix; + /* 64 */ float ratio; + + // Interpolations + /* 68 */ float blur_t; + /* 72 */ float opacity_t; + /* 76 */ float gapwidth_t; + /* 80 */ float offset_t; + /* 84 */ float width_t; + /* 88 */ float pattern_from_t; + /* 92 */ float pattern_to_t; + /* 96 */ +}; +static_assert(sizeof(LinePatternDrawableUBO) == 6 * 16); + +struct alignas(16) LinePatternTilePropsUBO { + /* 0 */ std::array pattern_from; + /* 16 */ std::array pattern_to; + /* 32 */ std::array scale; + /* 48 */ std::array texsize; + /* 56 */ float fade; + /* 60 */ float pad1; + /* 64 */ +}; +static_assert(sizeof(LinePatternTilePropsUBO) == 4 * 16); + +// +// Line SDF + +struct alignas(16) LineSDFDrawableUBO { + /* 0 */ std::array matrix; + /* 64 */ std::array patternscale_a; + /* 72 */ std::array patternscale_b; + /* 80 */ float tex_y_a; + /* 84 */ float tex_y_b; + /* 88 */ float ratio; + + // Interpolations + /* 92 */ float color_t; + /* 96 */ float blur_t; + /* 100 */ float opacity_t; + /* 104 */ float gapwidth_t; + /* 108 */ float offset_t; + /* 112 */ float width_t; + /* 116 */ float floorwidth_t; + /* 120 */ float pad1; + /* 124 */ float pad2; + /* 128 */ +}; +static_assert(sizeof(LineSDFDrawableUBO) == 8 * 16); + +struct alignas(16) LineSDFTilePropsUBO { + /* 0 */ float sdfgamma; + /* 4 */ float mix; + /* 8 */ float pad1; + /* 12 */ float pad2; + /* 16 */ +}; +static_assert(sizeof(LineSDFTilePropsUBO) == 16); + +/// Expression properties that do not depend on the tile enum class LineExpressionMask : uint32_t { None = 0, Color = 1 << 0, @@ -22,27 +125,6 @@ enum class LineExpressionMask : uint32_t { Offset = 1 << 6, }; -// -// Line - -struct alignas(16) LineDrawableUBO { - std::array matrix; - float ratio; - float pad1, pad2, pad3; -}; -static_assert(sizeof(LineDrawableUBO) % 16 == 0); - -struct alignas(16) LineInterpolationUBO { - float color_t; - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float pad1, pad2; -}; -static_assert(sizeof(LineInterpolationUBO) % 16 == 0); - struct alignas(16) LineExpressionUBO { gfx::GPUExpression color; gfx::GPUExpression blur; @@ -54,94 +136,36 @@ struct alignas(16) LineExpressionUBO { }; static_assert(sizeof(LineExpressionUBO) % 16 == 0); -// -// Line gradient - -using LineGradientDrawableUBO = LineDrawableUBO; - -struct alignas(16) LineGradientInterpolationUBO { - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float pad1, pad2, pad3; +/// Evaluated properties that do not depend on the tile +struct alignas(16) LineEvaluatedPropsUBO { + /* 0 */ Color color; + /* 16 */ float blur; + /* 20 */ float opacity; + /* 24 */ float gapwidth; + /* 28 */ float offset; + /* 32 */ float width; + /* 36 */ float floorwidth; + /* 40 */ LineExpressionMask expressionMask; + /* 44 */ float pad1; + /* 48 */ }; -static_assert(sizeof(LineGradientInterpolationUBO) % 16 == 0); - -// -// Line pattern +static_assert(sizeof(LineEvaluatedPropsUBO) == 3 * 16); -struct alignas(16) LinePatternDrawableUBO { - std::array matrix; - std::array scale; - std::array texsize; - float ratio; - float fade; -}; -static_assert(sizeof(LinePatternDrawableUBO) % 16 == 0); - -struct alignas(16) LinePatternInterpolationUBO { - float blur_t; - float opacity_t; - float offset_t; - float gapwidth_t; - float width_t; - float pattern_from_t; - float pattern_to_t; - float pad1; -}; -static_assert(sizeof(LinePatternInterpolationUBO) % 16 == 0); +#if MLN_UBO_CONSOLIDATION -struct alignas(16) LinePatternTilePropertiesUBO { - std::array pattern_from; - std::array pattern_to; +union LineDrawableUnionUBO { + LineDrawableUBO lineDrawableUBO; + LineGradientDrawableUBO lineGradientDrawableUBO; + LinePatternDrawableUBO linePatternDrawableUBO; + LineSDFDrawableUBO lineSDFDrawableUBO; }; -static_assert(sizeof(LinePatternTilePropertiesUBO) % 16 == 0); - -// -// Line SDF -struct alignas(16) LineSDFDrawableUBO { - std::array matrix; - std::array patternscale_a; - std::array patternscale_b; - float ratio; - float tex_y_a; - float tex_y_b; - float sdfgamma; - float mix; - float pad1, pad2, pad3; -}; -static_assert(sizeof(LineSDFDrawableUBO) % 16 == 0); - -struct alignas(16) LineSDFInterpolationUBO { - float color_t; - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float floorwidth_t; - float pad1; +union LineTilePropsUnionUBO { + LinePatternTilePropsUBO linePatternTilePropsUBO; + LineSDFTilePropsUBO lineSDFTilePropsUBO; }; -static_assert(sizeof(LineSDFInterpolationUBO) % 16 == 0); - -// -// Line evaluated properties -struct alignas(16) LineEvaluatedPropsUBO { - Color color; - float blur; - float opacity; - float gapwidth; - float offset; - float width; - float floorwidth; - LineExpressionMask expressionMask; - float pad1; -}; -static_assert(sizeof(LineEvaluatedPropsUBO) % 16 == 0); +#endif } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/location_indicator_ubo.hpp b/include/mbgl/shaders/location_indicator_ubo.hpp new file mode 100644 index 00000000000..797550ee70e --- /dev/null +++ b/include/mbgl/shaders/location_indicator_ubo.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace mbgl { +namespace shaders { + +struct alignas(16) LocationIndicatorDrawableUBO { + /* 0 */ std::array matrix; + /* 64 */ Color color; + /* 80 */ +}; +static_assert(sizeof(LocationIndicatorDrawableUBO) == 5 * 16); + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index 45211edbdf8..ec1b11899b1 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -2,12 +2,77 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define BACKGROUND_SHADER_COMMON R"( + +// +// Background + +struct alignas(16) BackgroundDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ +}; +static_assert(sizeof(BackgroundDrawableUBO) == 4 * 16, "wrong size"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) BackgroundPropsUBO { + /* 0 */ float4 color; + /* 16 */ float opacity; + /* 20 */ float pad1; + /* 24 */ float pad2; + /* 28 */ float pad3; + /* 32 */ +}; +static_assert(sizeof(BackgroundPropsUBO) == 2 * 16, "wrong size"); + +// +// Background pattern + +struct alignas(16) BackgroundPatternDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float2 pixel_coord_upper; + /* 72 */ float2 pixel_coord_lower; + /* 80 */ float tile_units_to_pixels; + /* 84 */ float pad1; + /* 88 */ float pad2; + /* 92 */ float pad3; + /* 96 */ +}; +static_assert(sizeof(BackgroundPatternDrawableUBO) == 6 * 16, "wrong size"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) BackgroundPatternPropsUBO { + /* 0 */ float2 pattern_tl_a; + /* 8 */ float2 pattern_br_a; + /* 16 */ float2 pattern_tl_b; + /* 24 */ float2 pattern_br_b; + /* 32 */ float2 pattern_size_a; + /* 40 */ float2 pattern_size_b; + /* 48 */ float scale_a; + /* 52 */ float scale_b; + /* 56 */ float mix; + /* 60 */ float opacity; + /* 64 */ +}; +static_assert(sizeof(BackgroundPatternPropsUBO) == 4 * 16, "wrong size"); + +union BackgroundDrawableUnionUBO { + BackgroundDrawableUBO backgroundDrawableUBO; + BackgroundPatternDrawableUBO backgroundPatternDrawableUBO; +}; + +enum { + idBackgroundDrawableUBO = globalUBOCount, + idBackgroundPropsUBO, + backgroundUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "BackgroundShader"; @@ -19,41 +84,108 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = BACKGROUND_SHADER_COMMON R"( #include using namespace metal; struct VertexStage { - short2 position [[attribute(3)]]; + short2 position [[attribute(backgroundUBOCount + 0)]]; }; struct FragmentStage { float4 position [[position, invariant]]; }; -struct alignas(16) BackgroundDrawableUBO { - float4x4 matrix; +FragmentStage vertex vertexMain(VertexStage in [[stage_in]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const BackgroundDrawableUnionUBO* drawableVector [[buffer(idBackgroundDrawableUBO)]]) { + + device const BackgroundDrawableUBO& drawable = drawableVector[uboIndex].backgroundDrawableUBO; + + return { + .position = drawable.matrix * float4(float2(in.position.xy), 0, 1) + }; +} + +half4 fragment fragmentMain(FragmentStage in [[stage_in]], + device const BackgroundPropsUBO& props [[buffer(idBackgroundPropsUBO)]]) { +#if defined(OVERDRAW_INSPECTOR) + return half4(1.0); +#endif + + return half4(props.color * props.opacity); +} +)"; }; -struct alignas(16) BackgroundLayerUBO { - float4 color; - float opacity; - float pad1, pad2, pad3; + +template <> +struct ShaderSource { + static constexpr auto name = "BackgroundPatternShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = BACKGROUND_SHADER_COMMON R"( +#include +using namespace metal; + +struct VertexStage { + short2 position [[attribute(backgroundUBOCount + 0)]]; +}; + +struct FragmentStage { + float4 position [[position, invariant]]; + float2 pos_a; + float2 pos_b; }; FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const BackgroundDrawableUBO& drawableUBO [[buffer(1)]]) { + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const BackgroundDrawableUnionUBO* drawableVector [[buffer(idBackgroundDrawableUBO)]], + device const BackgroundPatternPropsUBO& props [[buffer(idBackgroundPropsUBO)]]) { + + device const BackgroundPatternDrawableUBO& drawable = drawableVector[uboIndex].backgroundPatternDrawableUBO; + + const float2 pos = float2(in.position); + const float2 pos_a = get_pattern_pos(drawable.pixel_coord_upper, + drawable.pixel_coord_lower, + props.scale_a * props.pattern_size_a, + drawable.tile_units_to_pixels, + pos); + const float2 pos_b = get_pattern_pos(drawable.pixel_coord_upper, + drawable.pixel_coord_lower, + props.scale_b * props.pattern_size_b, + drawable.tile_units_to_pixels, + pos); return { - .position = drawableUBO.matrix * float4(float2(in.position.xy), 0, 1) + .position = drawable.matrix * float4(float2(in.position.xy), 0, 1), + .pos_a = pos_a, + .pos_b = pos_b, }; } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const BackgroundLayerUBO& layerUBO [[buffer(2)]]) { + device const GlobalPaintParamsUBO& paintParamsUBO [[buffer(idGlobalPaintParamsUBO)]], + device const BackgroundPatternPropsUBO& props [[buffer(idBackgroundPropsUBO)]], + texture2d image [[texture(0)]], + sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif - return half4(layerUBO.color * layerUBO.opacity); + const float2 texsize = paintParamsUBO.pattern_atlas_texsize; + const float2 imagecoord = glMod(float2(in.pos_a), 1.0); + const float2 pos = mix(props.pattern_tl_a / texsize, props.pattern_br_a / texsize, imagecoord); + const float4 color1 = image.sample(image_sampler, pos); + const float2 imagecoord_b = glMod(float2(in.pos_b), 1.0); + const float2 pos2 = mix(props.pattern_tl_b / texsize, props.pattern_br_b / texsize, imagecoord_b); + const float4 color2 = image.sample(image_sampler, pos2); + + return half4(mix(color1, color2, props.mix) * props.opacity); } )"; }; diff --git a/include/mbgl/shaders/mtl/background_pattern.hpp b/include/mbgl/shaders/mtl/background_pattern.hpp deleted file mode 100644 index 408cbd2fe4e..00000000000 --- a/include/mbgl/shaders/mtl/background_pattern.hpp +++ /dev/null @@ -1,97 +0,0 @@ -#pragma once - -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr auto name = "BackgroundPatternShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = R"( -#include -using namespace metal; - -struct VertexStage { - short2 position [[attribute(3)]]; -}; - -struct FragmentStage { - float4 position [[position, invariant]]; - float2 pos_a; - float2 pos_b; -}; - -struct alignas(16) BackgroundPatternDrawableUBO { - float4x4 matrix; - float2 pixel_coord_upper; - float2 pixel_coord_lower; - float tile_units_to_pixels; - float pad1, pad2, pad3; -}; -struct alignas(16) BackgroundPatternLayerUBO { - float2 pattern_tl_a; - float2 pattern_br_a; - float2 pattern_tl_b; - float2 pattern_br_b; - float2 pattern_size_a; - float2 pattern_size_b; - float scale_a; - float scale_b; - float mix; - float opacity; -}; - -FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const BackgroundPatternDrawableUBO& drawableUBO [[buffer(1)]], - device const BackgroundPatternLayerUBO& layerUBO [[buffer(2)]]) { - const float2 pos = float2(in.position); - const float2 pos_a = get_pattern_pos(drawableUBO.pixel_coord_upper, - drawableUBO.pixel_coord_lower, - layerUBO.scale_a * layerUBO.pattern_size_a, - drawableUBO.tile_units_to_pixels, - pos); - const float2 pos_b = get_pattern_pos(drawableUBO.pixel_coord_upper, - drawableUBO.pixel_coord_lower, - layerUBO.scale_b * layerUBO.pattern_size_b, - drawableUBO.tile_units_to_pixels, - pos); - return { - .position = drawableUBO.matrix * float4(float2(in.position.xy), 0, 1), - .pos_a = pos_a, - .pos_b = pos_b, - }; -} - -half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const GlobalPaintParamsUBO& paintParamsUBO [[buffer(0)]], - device const BackgroundPatternLayerUBO& layerUBO [[buffer(2)]], - texture2d image [[texture(0)]], - sampler image_sampler [[sampler(0)]]) { -#if defined(OVERDRAW_INSPECTOR) - return half4(1.0); -#endif - - const float2 texsize = paintParamsUBO.pattern_atlas_texsize; - const float2 imagecoord = glMod(float2(in.pos_a), 1.0); - const float2 pos = mix(layerUBO.pattern_tl_a / texsize, layerUBO.pattern_br_a / texsize, imagecoord); - const float4 color1 = image.sample(image_sampler, pos); - const float2 imagecoord_b = glMod(float2(in.pos_b), 1.0); - const float2 pos2 = mix(layerUBO.pattern_tl_b / texsize, layerUBO.pattern_br_b / texsize, imagecoord_b); - const float4 color2 = image.sample(image_sampler, pos2); - - return half4(mix(color1, color2, layerUBO.mix) * layerUBO.opacity); -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index 94b22fb1523..ed4efba8bac 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -2,47 +2,91 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define CIRCLE_SHADER_PRELUDE R"( + +struct alignas(16) CircleDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float2 extrude_scale; + + // Interpolations + /* 72 */ float color_t; + /* 76 */ float radius_t; + /* 80 */ float blur_t; + /* 84 */ float opacity_t; + /* 88 */ float stroke_color_t; + /* 92 */ float stroke_width_t; + /* 96 */ float stroke_opacity_t; + /* 100 */ float pad1; + /* 104 */ float pad2; + /* 108 */ float pad3; + /* 112 */ +}; +static_assert(sizeof(CircleDrawableUBO) == 7 * 16, "wrong size"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) CircleEvaluatedPropsUBO { + /* 0 */ float4 color; + /* 16 */ float4 stroke_color; + /* 32 */ float radius; + /* 36 */ float blur; + /* 40 */ float opacity; + /* 44 */ float stroke_width; + /* 48 */ float stroke_opacity; + /* 52 */ int scale_with_map; + /* 56 */ int pitch_with_map; + /* 60 */ float pad1; + /* 64 */ +}; +static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16, "wrong size"); + +enum { + idCircleDrawableUBO = globalUBOCount, + idCircleEvaluatedPropsUBO, + circleUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "CircleShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = CIRCLE_SHADER_PRELUDE R"( struct VertexStage { - short2 position [[attribute(4)]]; + short2 position [[attribute(circleUBOCount + 0)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(5)]]; + float4 color [[attribute(circleUBOCount + 1)]]; #endif #if !defined(HAS_UNIFORM_u_radius) - float2 radius [[attribute(6)]]; + float2 radius [[attribute(circleUBOCount + 2)]]; #endif #if !defined(HAS_UNIFORM_u_blur) - float2 blur [[attribute(7)]]; + float2 blur [[attribute(circleUBOCount + 3)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(8)]]; + float2 opacity [[attribute(circleUBOCount + 4)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_color) - float4 stroke_color [[attribute(9)]]; + float4 stroke_color [[attribute(circleUBOCount + 5)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_width) - float2 stroke_width [[attribute(10)]]; + float2 stroke_width [[attribute(circleUBOCount + 6)]]; #endif #if !defined(HAS_UNIFORM_u_stroke_opacity) - float2 stroke_opacity [[attribute(11)]]; + float2 stroke_opacity [[attribute(circleUBOCount + 7)]]; #endif }; @@ -74,55 +118,24 @@ struct FragmentStage { #endif }; -struct alignas(16) CircleDrawableUBO { - float4x4 matrix; - float2 extrude_scale; - float2 padding; -}; -struct alignas(16) CirclePaintParamsUBO { - float camera_to_center_distance; - float pad1,pad2,pad3; -}; -struct alignas(16) CircleEvaluatedPropsUBO { - float4 color; - float4 stroke_color; - float radius; - float blur; - float opacity; - float stroke_width; - float stroke_opacity; - int scale_with_map; - int pitch_with_map; - float padding; -}; - -struct alignas(16) CircleInterpolateUBO { - float color_t; - float radius_t; - float blur_t; - float opacity_t; - float stroke_color_t; - float stroke_width_t; - float stroke_opacity_t; - float pad1_; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const CircleDrawableUBO& drawable [[buffer(1)]], - device const CircleInterpolateUBO& interp [[buffer(2)]], - device const CircleEvaluatedPropsUBO& props [[buffer(3)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const CircleDrawableUBO* drawableVector [[buffer(idCircleDrawableUBO)]], + device const CircleEvaluatedPropsUBO& props [[buffer(idCircleEvaluatedPropsUBO)]]) { + + device const CircleDrawableUBO& drawable = drawableVector[uboIndex]; #if defined(HAS_UNIFORM_u_radius) const auto radius = props.radius; #else - const auto radius = unpack_mix_float(vertx.radius, interp.radius_t); + const auto radius = unpack_mix_float(vertx.radius, drawable.radius_t); #endif #if defined(HAS_UNIFORM_u_stroke_width) const auto stroke_width = props.stroke_width; #else - const auto stroke_width = unpack_mix_float(vertx.stroke_width, interp.stroke_width_t); + const auto stroke_width = unpack_mix_float(vertx.stroke_width, drawable.stroke_width_t); #endif // unencode the extrusion vector that we snuck into the a_pos vector @@ -165,31 +178,31 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], .antialiasblur = antialiasblur, #if !defined(HAS_UNIFORM_u_color) - .color = half4(unpack_mix_color(vertx.color, interp.color_t)), + .color = half4(unpack_mix_color(vertx.color, drawable.color_t)), #endif #if !defined(HAS_UNIFORM_u_radius) .radius = radius, #endif #if !defined(HAS_UNIFORM_u_blur) - .blur = half(unpack_mix_float(vertx.blur, interp.blur_t)), + .blur = half(unpack_mix_float(vertx.blur, drawable.blur_t)), #endif #if !defined(HAS_UNIFORM_u_opacity) - .opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)), + .opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)), #endif #if !defined(HAS_UNIFORM_u_stroke_color) - .stroke_color = half4(unpack_mix_color(vertx.stroke_color, interp.stroke_color_t)), + .stroke_color = half4(unpack_mix_color(vertx.stroke_color, drawable.stroke_color_t)), #endif #if !defined(HAS_UNIFORM_u_stroke_width) .stroke_width = half(stroke_width), #endif #if !defined(HAS_UNIFORM_u_stroke_opacity) - .stroke_opacity = half(unpack_mix_float(vertx.stroke_opacity, interp.stroke_opacity_t)), + .stroke_opacity = half(unpack_mix_float(vertx.stroke_opacity, drawable.stroke_opacity_t)), #endif }; } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CircleEvaluatedPropsUBO& props [[buffer(3)]]) { + device const CircleEvaluatedPropsUBO& props [[buffer(idCircleEvaluatedPropsUBO)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index 6791cd46c8a..a740eecfade 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -9,11 +9,35 @@ namespace shaders { struct alignas(16) ClipUBO { /* 0 */ std::array matrix; /* 64 */ std::uint32_t stencil_ref; - /* 68 */ std::uint32_t pad1, pad2, pad3; + /* 68 */ float pad1; + /* 72 */ float pad2; + /* 76 */ float pad3; /* 80 */ }; static_assert(sizeof(ClipUBO) == 5 * 16); +#define CLIPPING_MASK_SHADER_PRELUDE R"( + +#include +using namespace metal; + +struct alignas(16) ClipUBO { + /* 0 */ float4x4 matrix; + /* 64 */ uint32_t stencil_ref; + /* 68 */ float pad1; + /* 72 */ float pad2; + /* 76 */ float pad3; + /* 80 */ +}; +static_assert(sizeof(ClipUBO) == 5 * 16, "wrong size"); + +enum { + idClippingMaskUBO = globalUBOCount, + clippingMaskUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "ClippingMaskProgram"; @@ -25,20 +49,9 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( -#include -using namespace metal; - -struct alignas(16) ClipUBO { - /* 0 */ float4x4 matrix; - /* 64 */ uint32_t stencil_ref; - /* 68 */ uint32_t pad1, pad2, pad3; - /* 80 */ -}; -static_assert(sizeof(ClipUBO) == 5 * 16, "unexpected padding"); - + static constexpr auto source = CLIPPING_MASK_SHADER_PRELUDE R"( struct VertexStage { - short2 position [[attribute(2)]]; + short2 position [[attribute(clippingMaskUBOCount + 0)]]; }; struct FragmentStage { @@ -51,7 +64,7 @@ struct FragmentResult { }; FragmentStage vertex vertexMain(VertexStage in [[stage_in]], - device const ClipUBO& clipUBO [[buffer(1)]]) { + device const ClipUBO& clipUBO [[buffer(idClippingMaskUBO)]]) { return { clipUBO.matrix * float4(float2(in.position.xy), 0, 1) }; } diff --git a/include/mbgl/shaders/mtl/collision.hpp b/include/mbgl/shaders/mtl/collision.hpp new file mode 100644 index 00000000000..1121cae3402 --- /dev/null +++ b/include/mbgl/shaders/mtl/collision.hpp @@ -0,0 +1,203 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace shaders { + +#define COLLISION_SHADER_COMMON R"( + +struct alignas(16) CollisionDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ +}; +static_assert(sizeof(CollisionDrawableUBO) == 4 * 16, "wrong size"); + +struct alignas(16) CollisionTilePropsUBO { + /* 0 */ float2 extrude_scale; + /* 8 */ float overscale_factor; + /* 12 */ float pad1; + /* 16 */ +}; +static_assert(sizeof(CollisionTilePropsUBO) == 16, "wrong size"); + +enum { + idCollisionDrawableUBO = globalUBOCount, + idCollisionTilePropsUBO, + collisionUBOCount +}; + +)" + +template <> +struct ShaderSource { + static constexpr auto name = "CollisionBoxShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = COLLISION_SHADER_COMMON R"( + +struct VertexStage { + short2 pos [[attribute(collisionUBOCount + 0)]]; + short2 anchor_pos [[attribute(collisionUBOCount + 1)]]; + short2 extrude [[attribute(collisionUBOCount + 2)]]; + ushort2 placed [[attribute(collisionUBOCount + 3)]]; + float2 shift [[attribute(collisionUBOCount + 4)]]; +}; + +struct FragmentStage { + float4 position [[position, invariant]]; + float placed; + float notUsed; +}; + +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const CollisionDrawableUBO& drawable [[buffer(idCollisionDrawableUBO)]], + device const CollisionTilePropsUBO& tileProps [[buffer(idCollisionTilePropsUBO)]]) { + + float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1); + float camera_to_anchor_distance = projectedPoint.w; + float collision_perspective_ratio = clamp( + 0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance), + 0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles + 4.0); + + float4 position = drawable.matrix * float4(float2(vertx.pos), 0.0, 1.0); + position.xy += (float2(vertx.extrude) + vertx.shift) * tileProps.extrude_scale * position.w * collision_perspective_ratio; + + float placed = float(vertx.placed.x); + float notUsed = float(vertx.placed.y); + + return { + .position = position, + .placed = placed, + .notUsed = notUsed, + }; +} + +half4 fragment fragmentMain(FragmentStage in [[stage_in]]) { + + float alpha = 0.5; + + // Red = collision, hide label + float4 color = float4(1.0, 0.0, 0.0, 1.0) * alpha; + + // Blue = no collision, label is showing + if (in.placed > 0.5) { + color = float4(0.0, 0.0, 1.0, 0.5) * alpha; + } + + if (in.notUsed > 0.5) { + // This box not used, fade it out + color *= 0.1; + } + + return half4(color); +} +)"; +}; + +template <> +struct ShaderSource { + static constexpr auto name = "CollisionCircleShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = COLLISION_SHADER_COMMON R"( + +struct VertexStage { + short2 pos [[attribute(collisionUBOCount + 0)]]; + short2 anchor_pos [[attribute(collisionUBOCount + 1)]]; + short2 extrude [[attribute(collisionUBOCount + 2)]]; + ushort2 placed [[attribute(collisionUBOCount + 3)]]; +}; + +struct FragmentStage { + float4 position [[position, invariant]]; + float placed; + float notUsed; + float radius; + float2 extrude; + float2 extrude_scale; +}; + +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const CollisionDrawableUBO& drawable [[buffer(idCollisionDrawableUBO)]], + device const CollisionTilePropsUBO& tileProps [[buffer(idCollisionTilePropsUBO)]]) { + + float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1); + float camera_to_anchor_distance = projectedPoint.w; + float collision_perspective_ratio = clamp( + 0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance), + 0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles + 4.0); + + float4 position = drawable.matrix * float4(float2(vertx.pos), 0.0, 1.0); + + float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur + position.xy += float2(vertx.extrude) * tileProps.extrude_scale * padding_factor * position.w * collision_perspective_ratio; + + float placed = float(vertx.placed.x); + float notUsed = float(vertx.placed.y); + float radius = abs(float(vertx.extrude.y)); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius + + float2 extrude = float2(vertx.extrude) * padding_factor; + float2 extrude_scale = tileProps.extrude_scale * paintParams.camera_to_center_distance * collision_perspective_ratio; + + return { + .position = position, + .placed = placed, + .notUsed = notUsed, + .radius = radius, + .extrude = extrude, + .extrude_scale = extrude_scale, + }; +} + +half4 fragment fragmentMain(FragmentStage in [[stage_in]], + device const CollisionTilePropsUBO& tileProps [[buffer(idCollisionTilePropsUBO)]]) { + + float alpha = 0.5; + + // Red = collision, hide label + float4 color = float4(1.0, 0.0, 0.0, 1.0) * alpha; + + // Blue = no collision, label is showing + if (in.placed > 0.5) { + color = float4(0.0, 0.0, 1.0, 0.5) * alpha; + } + + if (in.notUsed > 0.5) { + // This box not used, fade it out + color *= 0.2; + } + + float extrude_scale_length = length(in.extrude_scale); + float extrude_length = length(in.extrude) * extrude_scale_length; + float stroke_width = 15.0 * extrude_scale_length / tileProps.overscale_factor; + float radius = in.radius * extrude_scale_length; + + float distance_to_edge = abs(extrude_length - radius); + float opacity_t = smoothstep(-stroke_width, 0.0, -distance_to_edge); + + return half4(opacity_t * color); +} +)"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/collision_box.hpp b/include/mbgl/shaders/mtl/collision_box.hpp deleted file mode 100644 index 1ae672a0740..00000000000 --- a/include/mbgl/shaders/mtl/collision_box.hpp +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr auto name = "CollisionBoxShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = R"( - -struct VertexStage { - short2 pos [[attribute(2)]]; - short2 anchor_pos [[attribute(3)]]; - short2 extrude [[attribute(4)]]; - ushort2 placed [[attribute(5)]]; - float2 shift [[attribute(6)]]; -}; - -struct FragmentStage { - float4 position [[position, invariant]]; - float placed; - float notUsed; -}; - -struct alignas(16) CollisionBoxUBO { - float4x4 matrix; - float2 extrude_scale; - float overscale_factor; - float pad1; -}; - -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const CollisionBoxUBO& drawable [[buffer(1)]]) { - - float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1); - float camera_to_anchor_distance = projectedPoint.w; - float collision_perspective_ratio = clamp( - 0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance), - 0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles - 4.0); - - float4 position = drawable.matrix * float4(float2(vertx.pos), 0.0, 1.0); - position.xy += (float2(vertx.extrude) + vertx.shift) * drawable.extrude_scale * position.w * collision_perspective_ratio; - - float placed = float(vertx.placed.x); - float notUsed = float(vertx.placed.y); - - return { - .position = position, - .placed = placed, - .notUsed = notUsed, - }; -} - -half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CollisionBoxUBO& drawable [[buffer(1)]]) { - - float alpha = 0.5; - - // Red = collision, hide label - float4 color = float4(1.0, 0.0, 0.0, 1.0) * alpha; - - // Blue = no collision, label is showing - if (in.placed > 0.5) { - color = float4(0.0, 0.0, 1.0, 0.5) * alpha; - } - - if (in.notUsed > 0.5) { - // This box not used, fade it out - color *= 0.1; - } - - return half4(color); -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/collision_circle.hpp b/include/mbgl/shaders/mtl/collision_circle.hpp deleted file mode 100644 index ecd009bc987..00000000000 --- a/include/mbgl/shaders/mtl/collision_circle.hpp +++ /dev/null @@ -1,112 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr auto name = "CollisionCircleShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = R"( - -struct VertexStage { - short2 pos [[attribute(2)]]; - short2 anchor_pos [[attribute(3)]]; - short2 extrude [[attribute(4)]]; - ushort2 placed [[attribute(5)]]; -}; - -struct FragmentStage { - float4 position [[position, invariant]]; - float placed; - float notUsed; - float radius; - float2 extrude; - float2 extrude_scale; -}; - -struct alignas(16) CollisionCircleUBO { - float4x4 matrix; - float2 extrude_scale; - float overscale_factor; - float pad1; -}; - -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const CollisionCircleUBO& drawable [[buffer(1)]]) { - - float4 projectedPoint = drawable.matrix * float4(float2(vertx.anchor_pos), 0, 1); - float camera_to_anchor_distance = projectedPoint.w; - float collision_perspective_ratio = clamp( - 0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance), - 0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles - 4.0); - - float4 position = drawable.matrix * float4(float2(vertx.pos), 0.0, 1.0); - - float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur - position.xy += float2(vertx.extrude) * drawable.extrude_scale * padding_factor * position.w * collision_perspective_ratio; - - float placed = float(vertx.placed.x); - float notUsed = float(vertx.placed.y); - float radius = abs(float(vertx.extrude.y)); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius - - float2 extrude = float2(vertx.extrude) * padding_factor; - float2 extrude_scale = drawable.extrude_scale * paintParams.camera_to_center_distance * collision_perspective_ratio; - - return { - .position = position, - .placed = placed, - .notUsed = notUsed, - .radius = radius, - .extrude = extrude, - .extrude_scale = extrude_scale, - }; -} - -half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const CollisionCircleUBO& drawable [[buffer(1)]]) { - - float alpha = 0.5; - - // Red = collision, hide label - float4 color = float4(1.0, 0.0, 0.0, 1.0) * alpha; - - // Blue = no collision, label is showing - if (in.placed > 0.5) { - color = float4(0.0, 0.0, 1.0, 0.5) * alpha; - } - - if (in.notUsed > 0.5) { - // This box not used, fade it out - color *= 0.2; - } - - float extrude_scale_length = length(in.extrude_scale); - float extrude_length = length(in.extrude) * extrude_scale_length; - float stroke_width = 15.0 * extrude_scale_length / drawable.overscale_factor; - float radius = in.radius * extrude_scale_length; - - float distance_to_edge = abs(extrude_length - radius); - float opacity_t = smoothstep(-stroke_width, 0.0, -distance_to_edge); - - return half4(opacity_t * color); -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/common.hpp b/include/mbgl/shaders/mtl/common.hpp index fc093b704b7..94fcff58dff 100644 --- a/include/mbgl/shaders/mtl/common.hpp +++ b/include/mbgl/shaders/mtl/common.hpp @@ -54,7 +54,12 @@ float4 unpack_mix_color(const float4 packedColors, const float t) { decode_color(float2(packedColors[2], packedColors[3])), t); } - +// Unpack pattern position +inline float2 get_pattern_pos(const float2 pixel_coord_upper, const float2 pixel_coord_lower, + const float2 pattern_size, const float tile_units_to_pixels, const float2 pos) { + const float2 offset = glMod(glMod(glMod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); + return (tile_units_to_pixels * pos + offset) / pattern_size; +} template ForwardIt upper_bound(ForwardIt first, ForwardIt last, thread const T& value) @@ -196,49 +201,9 @@ struct alignas(16) GPUExpression { float4 getColor(size_t index) device const { return decode_color(stops.colors[index]); } }; -static_assert(sizeof(GPUExpression) == 32 + (4 + 8) * maxExprStops, "wrong alignment"); +static_assert(sizeof(GPUExpression) == 32 + (4 + 8) * maxExprStops, "wrong size"); static_assert(sizeof(GPUExpression) % 16 == 0, "wrong alignment"); - -enum { - idGlobalPaintParamsUBO, - globalUBOCount -}; - -enum { - idLineDrawableUBO = globalUBOCount, - idLineInterpolationUBO, - idLineTilePropertiesUBO, - idLineEvaluatedPropsUBO, - idLineExpressionUBO, - lineUBOCount -}; - - -enum class LineExpressionMask : uint32_t { - None = 0, - Color = 1 << 0, - Opacity = 1 << 1, - Blur = 1 << 2, - Width = 1 << 3, - GapWidth = 1 << 4, - FloorWidth = 1 << 5, - Offset = 1 << 6, -}; -bool operator&(LineExpressionMask a, LineExpressionMask b) { return (uint32_t)a & (uint32_t)b; } - -struct alignas(16) LineExpressionUBO { - GPUExpression color; - GPUExpression blur; - GPUExpression opacity; - GPUExpression gapwidth; - GPUExpression offset; - GPUExpression width; - GPUExpression floorwidth; -}; -static_assert(sizeof(LineExpressionUBO) % 16 == 0, "wrong alignment"); - - struct alignas(16) GlobalPaintParamsUBO { /* 0 */ float2 pattern_atlas_texsize; /* 8 */ float2 units_to_pixels; @@ -247,136 +212,17 @@ struct alignas(16) GlobalPaintParamsUBO { /* 28 */ float symbol_fade_change; /* 32 */ float aspect_ratio; /* 36 */ float pixel_ratio; - /* 40 */ float zoom; + /* 40 */ float map_zoom; /* 44 */ float pad1; /* 48 */ }; -static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16, "unexpected padding"); - -struct alignas(16) FillEvaluatedPropsUBO { - float4 color; - float4 outline_color; - float opacity; - float fade; - float from_scale; - float to_scale; -}; - -struct alignas(16) FillExtrusionDrawableUBO { - /* 0 */ float4x4 matrix; - /* 64 */ float2 texsize; - /* 72 */ float2 pixel_coord_upper; - /* 80 */ float2 pixel_coord_lower; - /* 88 */ float height_factor; - /* 92 */ float tile_ratio; - /* 96 */ -}; -static_assert(sizeof(FillExtrusionDrawableUBO) == 6 * 16, "unexpected padding"); +static_assert(sizeof(GlobalPaintParamsUBO) == 3 * 16, "wrong size"); -struct alignas(16) FillExtrusionPropsUBO { - /* 0 */ float4 color; - /* 16 */ float4 light_color_pad; - /* 32 */ float4 light_position_base; - /* 48 */ float height; - /* 52 */ float light_intensity; - /* 56 */ float vertical_gradient; - /* 60 */ float opacity; - /* 64 */ float fade; - /* 68 */ float from_scale; - /* 72 */ float to_scale; - /* 76 */ float pad2; - /* 80 */ -}; -static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "unexpected padding"); - -struct alignas(16) FillExtrusionTilePropsUBO { - /* 0 */ float4 pattern_from; - /* 16 */ float4 pattern_to; - /* 32 */ -}; -static_assert(sizeof(FillExtrusionTilePropsUBO) == 2 * 16, "unexpected padding"); - -struct alignas(16) FillExtrusionInterpolateUBO { - /* 0 */ float base_t; - /* 4 */ float height_t; - /* 8 */ float color_t; - /* 12 */ float pattern_from_t; - /* 16 */ float pattern_to_t; - /* 20 */ float pad1, pad2, pad3; - /* 32 */ -}; -static_assert(sizeof(FillExtrusionInterpolateUBO) == 2 * 16, "unexpected padding"); - -struct alignas(16) LineEvaluatedPropsUBO { - float4 color; - float blur; - float opacity; - float gapwidth; - float offset; - float width; - float floorwidth; - LineExpressionMask expressionMask; - float pad1; -}; - -struct alignas(16) SymbolDrawableUBO { - float4x4 matrix; - float4x4 label_plane_matrix; - float4x4 coord_matrix; - - float2 texsize; - float2 texsize_icon; - - float gamma_scale; - /*bool*/ int rotate_symbol; - float2 pad; -}; -static_assert(sizeof(SymbolDrawableUBO) == 14 * 16, "unexpected padding"); - -struct alignas(16) SymbolTilePropsUBO { - /*bool*/ int is_text; - /*bool*/ int is_halo; - /*bool*/ int pitch_with_map; - /*bool*/ int is_size_zoom_constant; - /*bool*/ int is_size_feature_constant; - float size_t; - float size; - float padding; -}; -static_assert(sizeof(SymbolTilePropsUBO) == 2 * 16, "unexpected padding"); - -struct alignas(16) SymbolInterpolateUBO { - float fill_color_t; - float halo_color_t; - float opacity_t; - float halo_width_t; - float halo_blur_t; - float pad1, pad2, pad3; -}; -static_assert(sizeof(SymbolInterpolateUBO) == 32, "unexpected padding"); - -struct alignas(16) SymbolEvaluatedPropsUBO { - float4 text_fill_color; - float4 text_halo_color; - float text_opacity; - float text_halo_width; - float text_halo_blur; - float pad1; - float4 icon_fill_color; - float4 icon_halo_color; - float icon_opacity; - float icon_halo_width; - float icon_halo_blur; - float pad2; +enum { + idGlobalPaintParamsUBO, + idGlobalUBOIndex, + globalUBOCount, }; -static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "unexpected padding"); - -// unpack pattern position -inline float2 get_pattern_pos(const float2 pixel_coord_upper, const float2 pixel_coord_lower, - const float2 pattern_size, const float tile_units_to_pixels, const float2 pos) { - const float2 offset = glMod(glMod(glMod(pixel_coord_upper, pattern_size) * 256.0, pattern_size) * 256.0 + pixel_coord_lower, pattern_size); - return (tile_units_to_pixels * pos + offset) / pattern_size; -} )"; diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index eec04b8161d..5f919e3dd28 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -1,43 +1,52 @@ #pragma once -#include -#include -#include #include +#include +#include namespace mbgl { namespace shaders { +#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"( + +struct alignas(16) CustomSymbolIconDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float2 extrude_scale; + /* 72 */ float2 anchor; + /* 80 */ float angle_degrees; + /* 84 */ uint32_t scale_with_map; + /* 88 */ uint32_t pitch_with_map; + /* 92 */ float camera_to_center_distance; + /* 96 */ float aspect_ratio; + /* 100 */ float pad1; + /* 104 */ float pad2; + /* 108 */ float pad3; + /* 112 */ +}; +static_assert(sizeof(CustomSymbolIconParametersUBO) == 7 * 16, "wrong size"); + +enum { + idCustomSymbolDrawableUBO = globalUBOCount, + customSymbolUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "CustomSymbolIconShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( -struct alignas(16) CustomSymbolIconDrawableUBO { - float4x4 matrix; -}; - -struct alignas(16) CustomSymbolIconParametersUBO { - float2 extrude_scale; - float2 anchor; - float angle_degrees; - int scale_with_map; - int pitch_with_map; - float camera_to_center_distance; - float aspect_ratio; - float pad0, pad1, pad3; -}; - + static constexpr auto source = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"( struct VertexStage { - float2 a_pos [[attribute(3)]]; - float2 a_tex [[attribute(4)]]; + float2 a_pos [[attribute(customSymbolUBOCount + 0)]]; + float2 a_tex [[attribute(customSymbolUBOCount + 1)]]; }; struct FragmentStage { @@ -59,29 +68,28 @@ float2 ellipseRotateVec2(float2 v, float angle, float radiusRatio /* A/B */) { } FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const CustomSymbolIconDrawableUBO& drawable [[buffer(1)]], - device const CustomSymbolIconParametersUBO& parameters [[buffer(2)]]) { + device const CustomSymbolIconDrawableUBO& drawable [[buffer(idCustomSymbolDrawableUBO)]]) { const float2 extrude = glMod(float2(vertx.a_pos), 2.0) * 2.0 - 1.0; - const float2 anchor = (parameters.anchor - float2(0.5, 0.5)) * 2.0; + const float2 anchor = (drawable.anchor - float2(0.5, 0.5)) * 2.0; const float2 center = floor(float2(vertx.a_pos) * 0.5); - const float angle = radians(-parameters.angle_degrees); + const float angle = radians(-drawable.angle_degrees); float2 corner = extrude - anchor; float4 position; - if (parameters.pitch_with_map) { - if (parameters.scale_with_map) { - corner *= parameters.extrude_scale; + if (drawable.pitch_with_map) { + if (drawable.scale_with_map) { + corner *= drawable.extrude_scale; } else { float4 projected_center = drawable.matrix * float4(center, 0, 1); - corner *= parameters.extrude_scale * (projected_center.w / parameters.camera_to_center_distance); + corner *= drawable.extrude_scale * (projected_center.w / drawable.camera_to_center_distance); } corner = center + rotateVec2(corner, angle); position = drawable.matrix * float4(corner, 0, 1); } else { position = drawable.matrix * float4(center, 0, 1); - const float factor = parameters.scale_with_map ? parameters.camera_to_center_distance : position.w; - position.xy += ellipseRotateVec2(corner * parameters.extrude_scale * factor, angle, parameters.aspect_ratio); + const float factor = drawable.scale_with_map ? drawable.camera_to_center_distance : position.w; + position.xy += ellipseRotateVec2(corner * drawable.extrude_scale * factor, angle, drawable.aspect_ratio); } return { diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index 162b480037f..498188765cc 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -2,12 +2,31 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define DEBUG_SHADER_PRELUDE R"( + +struct alignas(16) DebugUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float4 color; + /* 80 */ float overlay_scale; + /* 84 */ float pad1; + /* 88 */ float pad2; + /* 92 */ float pad3; + /* 96 */ +}; +static_assert(sizeof(DebugUBO) == 6 * 16, "wrong size"); + +enum { + idDebugUBO = globalUBOCount, + debugUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "DebugShader"; @@ -19,10 +38,10 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = DEBUG_SHADER_PRELUDE R"( struct VertexStage { - short2 pos [[attribute(2)]]; + short2 pos [[attribute(debugUBOCount + 0)]]; }; struct FragmentStage { @@ -30,15 +49,8 @@ struct FragmentStage { float2 uv; }; -struct alignas(16) DebugUBO { - float4x4 matrix; - float4 color; - float overlay_scale; - float pad1, pad2, pad3; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const DebugUBO& debug [[buffer(1)]]) { + device const DebugUBO& debug [[buffer(idDebugUBO)]]) { const float4 position = debug.matrix * float4(float2(vertx.pos) * debug.overlay_scale, 0, 1); @@ -53,7 +65,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const DebugUBO& debug [[buffer(1)]], + device const DebugUBO& debug [[buffer(idDebugUBO)]], texture2d overlay [[texture(0)]], sampler overlay_sampler [[sampler(0)]]) { diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index 5cf49dc8753..37d7c88d7be 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -2,33 +2,165 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define FILL_SHADER_COMMON R"( + +// +// Fill + +struct alignas(16) FillDrawableUBO { + /* 0 */ float4x4 matrix; + + // Interpolations + /* 64 */ float color_t; + /* 68 */ float opacity_t; + /* 72 */ float pad1; + /* 76 */ float pad2; + /* 80 */ +}; +static_assert(sizeof(FillDrawableUBO) == 5 * 16, "wrong size"); + +// +// Fill outline + +struct alignas(16) FillOutlineDrawableUBO { + /* 0 */ float4x4 matrix; + + // Interpolations + /* 64 */ float outline_color_t; + /* 68 */ float opacity_t; + /* 72 */ float pad1; + /* 76 */ float pad2; + /* 80 */ +}; +static_assert(sizeof(FillOutlineDrawableUBO) == 5 * 16, "wrong size"); + +// +// Fill pattern + +struct alignas(16) FillPatternDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float2 pixel_coord_upper; + /* 72 */ float2 pixel_coord_lower; + /* 80 */ float tile_ratio; + + // Interpolations + /* 84 */ float pattern_from_t; + /* 88 */ float pattern_to_t; + /* 92 */ float opacity_t; + /* 96 */ +}; +static_assert(sizeof(FillPatternDrawableUBO) == 6 * 16, "wrong size"); + +struct alignas(16) FillPatternTilePropsUBO { + /* 0 */ float4 pattern_from; + /* 16 */ float4 pattern_to; + /* 32 */ float2 texsize; + /* 40 */ float pad1; + /* 44 */ float pad2; + /* 48 */ +}; +static_assert(sizeof(FillPatternTilePropsUBO) == 3 * 16, "wrong size"); + +// +// Fill pattern outline + +struct alignas(16) FillOutlinePatternDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float2 pixel_coord_upper; + /* 72 */ float2 pixel_coord_lower; + /* 80 */ float tile_ratio; + + // Interpolations + /* 84 */ float pattern_from_t; + /* 88 */ float pattern_to_t; + /* 92 */ float opacity_t; + /* 96 */ +}; +static_assert(sizeof(FillOutlinePatternDrawableUBO) == 6 * 16, "wrong size"); + +struct alignas(16) FillOutlinePatternTilePropsUBO { + /* 0 */ float4 pattern_from; + /* 16 */ float4 pattern_to; + /* 32 */ float2 texsize; + /* 40 */ float pad1; + /* 44 */ float pad2; + /* 48 */ +}; +static_assert(sizeof(FillOutlinePatternTilePropsUBO) == 3 * 16, "wrong size"); + +// +// Fill outline triangulated + +struct alignas(16) FillOutlineTriangulatedDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float ratio; + /* 68 */ float pad1; + /* 72 */ float pad2; + /* 76 */ float pad3; + /* 80 */ +}; +static_assert(sizeof(FillOutlineTriangulatedDrawableUBO) == 5 * 16, "wrong size"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) FillEvaluatedPropsUBO { + /* 0 */ float4 color; + /* 16 */ float4 outline_color; + /* 32 */ float opacity; + /* 36 */ float fade; + /* 40 */ float from_scale; + /* 44 */ float to_scale; + /* 48 */ +}; +static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16, "wrong size"); + +union FillDrawableUnionUBO { + FillDrawableUBO fillDrawableUBO; + FillOutlineDrawableUBO fillOutlineDrawableUBO; + FillPatternDrawableUBO fillPatternDrawableUBO; + FillOutlinePatternDrawableUBO fillOutlinePatternDrawableUBO; + FillOutlineTriangulatedDrawableUBO fillOutlineTriangulatedDrawableUBO; +}; + +union FillTilePropsUnionUBO { + FillPatternTilePropsUBO fillPatternTilePropsUBO; + FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO; +}; + +enum { + idFillDrawableUBO = globalUBOCount, + idFillTilePropsUBO, + idFillEvaluatedPropsUBO, + fillUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "FillShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { - short2 position [[attribute(5)]]; + short2 position [[attribute(fillUBOCount + 0)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(6)]]; + float4 color [[attribute(fillUBOCount + 1)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(7)]]; + float2 opacity [[attribute(fillUBOCount + 2)]]; #endif }; @@ -43,32 +175,25 @@ struct FragmentStage { #endif }; -struct alignas(16) FillDrawableUBO { - float4x4 matrix; -}; +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]]) { -struct alignas(16) FillInterpolateUBO { - float color_t; - float opacity_t; -}; + device const FillDrawableUBO& drawable = drawableVector[uboIndex].fillDrawableUBO; -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillDrawableUBO& drawable [[buffer(1)]], - device const FillInterpolateUBO& interp [[buffer(3)]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { return { .position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f), #if !defined(HAS_UNIFORM_u_color) - .color = half4(unpack_mix_color(vertx.color, interp.color_t)), + .color = half4(unpack_mix_color(vertx.color, drawable.color_t)), #endif #if !defined(HAS_UNIFORM_u_opacity) - .opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)), + .opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)), #endif }; } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif @@ -96,16 +221,16 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { - short2 position [[attribute(5)]]; - float4 outline_color [[attribute(6)]]; - float2 opacity [[attribute(7)]]; + short2 position [[attribute(fillUBOCount + 0)]]; + float4 outline_color [[attribute(fillUBOCount + 1)]]; + float2 opacity [[attribute(fillUBOCount + 2)]]; }; struct FragmentStage { @@ -119,35 +244,28 @@ struct FragmentStage { #endif }; -struct alignas(16) FillOutlineDrawableUBO { - float4x4 matrix; -}; +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]]) { -struct alignas(16) FillOutlineInterpolateUBO { - float outline_color_t; - float opacity_t; -}; + device const FillOutlineDrawableUBO& drawable = drawableVector[uboIndex].fillOutlineDrawableUBO; -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const FillOutlineDrawableUBO& drawable [[buffer(1)]], - device const FillOutlineInterpolateUBO& interp [[buffer(3)]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { const float4 position = drawable.matrix * float4(float2(vertx.position), 0.0f, 1.0f); return { .position = position, .pos = (position.xy / position.w + 1.0) / 2.0 * paintParams.world_size, #if !defined(HAS_UNIFORM_u_outline_color) - .outline_color = half4(unpack_mix_color(vertx.outline_color, interp.outline_color_t)), + .outline_color = half4(unpack_mix_color(vertx.outline_color, drawable.outline_color_t)), #endif #if !defined(HAS_UNIFORM_u_opacity) - .opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)), + .opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)), #endif }; } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif @@ -181,23 +299,23 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { - short2 position [[attribute(5)]]; + short2 position [[attribute(fillUBOCount + 0)]]; #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(6)]]; + ushort4 pattern_from [[attribute(fillUBOCount + 1)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(7)]]; + ushort4 pattern_to [[attribute(fillUBOCount + 2)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(8)]]; + float2 opacity [[attribute(fillUBOCount + 3)]]; #endif }; @@ -217,32 +335,16 @@ struct FragmentStage { #endif }; -struct alignas(16) FillPatternDrawableUBO { - float4x4 matrix; - float2 pixel_coord_upper; - float2 pixel_coord_lower; - float2 texsize; - float tile_ratio; - float pad; -}; +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]], + device const FillTilePropsUnionUBO* tilePropsVector [[buffer(idFillTilePropsUBO)]], + device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) { -struct alignas(16) FillPatternTilePropsUBO { - float4 pattern_from; - float4 pattern_to; -}; + device const FillPatternDrawableUBO& drawable = drawableVector[uboIndex].fillPatternDrawableUBO; + device const FillPatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].fillPatternTilePropsUBO; -struct alignas(16) FillPatternInterpolateUBO { - float pattern_from_t; - float pattern_to_t; - float opacity_t; -}; - -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const FillPatternDrawableUBO& drawable [[buffer(1)]], - device const FillPatternTilePropsUBO& tileProps [[buffer(2)]], - device const FillPatternInterpolateUBO& interp [[buffer(3)]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(HAS_UNIFORM_u_pattern_from) const auto pattern_from = float4(tileProps.pattern_from); #else @@ -280,21 +382,23 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], .pattern_to = half4(pattern_to), #endif #if !defined(HAS_UNIFORM_u_opacity) - .opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)), + .opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)), #endif }; } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillPatternDrawableUBO& drawable [[buffer(1)]], - device const FillPatternTilePropsUBO& tileProps [[buffer(2)]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillTilePropsUnionUBO* tilePropsVector [[buffer(idFillTilePropsUBO)]], + device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif + device const FillPatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].fillPatternTilePropsUBO; + #if defined(HAS_UNIFORM_u_pattern_from) const auto pattern_from = float4(tileProps.pattern_from); #else @@ -319,11 +423,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], const float2 pattern_br_b = pattern_to.zw; const float2 imagecoord = glMod(in.v_pos_a, 1.0); - const float2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord); + const float2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord); const float4 color1 = image0.sample(image0_sampler, pos); const float2 imagecoord_b = glMod(in.v_pos_b, 1.0); - const float2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b); + const float2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b); const float4 color2 = image0.sample(image0_sampler, pos2); return half4(mix(color1, color2, props.fade) * opacity); @@ -337,24 +441,24 @@ struct ShaderSource uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { - short2 position [[attribute(5)]]; + short2 position [[attribute(fillUBOCount + 0)]]; #if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(6)]]; + ushort4 pattern_from [[attribute(fillUBOCount + 1)]]; #endif #if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(7)]]; + ushort4 pattern_to [[attribute(fillUBOCount + 2)]]; #endif #if !defined(HAS_UNIFORM_u_opacity) - float2 opacity [[attribute(8)]]; + float2 opacity [[attribute(fillUBOCount + 3)]]; #endif }; @@ -375,32 +479,16 @@ struct FragmentStage { #endif }; -struct alignas(16) FillOutlinePatternDrawableUBO { - float4x4 matrix; - float2 pixel_coord_upper; - float2 pixel_coord_lower; - float2 texsize; - float tile_ratio; - float pad; -}; - -struct alignas(16) FillOutlinePatternTilePropsUBO { - float4 pattern_from; - float4 pattern_to; -}; +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]], + device const FillTilePropsUnionUBO* tilePropsVector [[buffer(idFillTilePropsUBO)]], + device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) { -struct alignas(16) FillOutlinePatternInterpolateUBO { - float pattern_from_t; - float pattern_to_t; - float opacity_t; -}; + device const FillOutlinePatternDrawableUBO& drawable = drawableVector[uboIndex].fillOutlinePatternDrawableUBO; + device const FillOutlinePatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].fillOutlinePatternTilePropsUBO; -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const FillOutlinePatternDrawableUBO& drawable [[buffer(1)]], - device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(2)]], - device const FillOutlinePatternInterpolateUBO& interp [[buffer(3)]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { #if defined(HAS_UNIFORM_u_pattern_from) const auto pattern_from = tileProps.pattern_from; #else @@ -414,7 +502,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], #endif #if !defined(HAS_UNIFORM_u_opacity) - const auto opacity = unpack_mix_float(vertx.opacity, interp.opacity_t); + const auto opacity = unpack_mix_float(vertx.opacity, drawable.opacity_t); #endif const float2 pattern_tl_a = pattern_from.xy; @@ -451,15 +539,17 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillOutlinePatternDrawableUBO& drawable [[buffer(1)]], - device const FillOutlinePatternTilePropsUBO& tileProps [[buffer(2)]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillTilePropsUnionUBO* tilePropsVector [[buffer(idFillTilePropsUBO)]], + device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif + device const FillOutlinePatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].fillOutlinePatternTilePropsUBO; + #if defined(HAS_UNIFORM_u_pattern_from) const auto pattern_from = float4(tileProps.pattern_from); #else @@ -484,11 +574,11 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], const float2 pattern_br_b = pattern_to.zw; const float2 imagecoord = glMod(in.v_pos_a, 1.0); - const float2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord); + const float2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord); const float4 color1 = image0.sample(image0_sampler, pos); const float2 imagecoord_b = glMod(in.v_pos_b, 1.0); - const float2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b); + const float2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b); const float4 color2 = image0.sample(image0_sampler, pos2); // TODO: Should triangate the lines into triangles to support thick line and edge antialiased. @@ -511,10 +601,10 @@ struct ShaderSource instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = FILL_SHADER_COMMON R"( struct VertexStage { - short2 pos_normal [[attribute(5)]]; - uchar4 data [[attribute(6)]]; + short2 pos_normal [[attribute(fillUBOCount + 0)]]; + uchar4 data [[attribute(fillUBOCount + 1)]]; }; struct FragmentStage { @@ -524,16 +614,12 @@ struct FragmentStage { half gamma_scale; }; -struct alignas(16) FillOutlineTriangulatedDrawableUBO { - float4x4 matrix; - float ratio; - float pad1, pad2, pad3; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const FillOutlineTriangulatedDrawableUBO& drawable [[buffer(1)]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillDrawableUnionUBO* drawableVector [[buffer(idFillDrawableUBO)]]) { + + device const FillOutlineTriangulatedDrawableUBO& drawable = drawableVector[uboIndex].fillOutlineTriangulatedDrawableUBO; // the distance over which the line edge fades out. // Retina devices need a smaller distance to avoid aliasing. @@ -571,7 +657,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const FillEvaluatedPropsUBO& props [[buffer(4)]]) { + device const FillEvaluatedPropsUBO& props [[buffer(idFillEvaluatedPropsUBO)]]) { // Calculate the distance of the pixel from the line in pixels. const float dist = length(in.normal) * in.width2; diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index 73440ccbc74..d1746d23de0 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -2,36 +2,91 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define FILL_EXTRUSION_SHADER_COMMON R"( + +struct alignas(16) FillExtrusionDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float2 pixel_coord_upper; + /* 72 */ float2 pixel_coord_lower; + /* 80 */ float height_factor; + /* 84 */ float tile_ratio; + + // Interpolations + /* 88 */ float base_t; + /* 92 */ float height_t; + /* 96 */ float color_t; + /* 100 */ float pattern_from_t; + /* 104 */ float pattern_to_t; + /* 108 */ float pad1; + /* 112 */ +}; +static_assert(sizeof(FillExtrusionDrawableUBO) == 7 * 16); + +struct alignas(16) FillExtrusionTilePropsUBO { + /* 0 */ float4 pattern_from; + /* 16 */ float4 pattern_to; + /* 32 */ float2 texsize; + /* 40 */ float pad1; + /* 44 */ float pad2; + /* 48 */ +}; +static_assert(sizeof(FillExtrusionTilePropsUBO) == 3 * 16); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) FillExtrusionPropsUBO { + /* 0 */ float4 color; + /* 16 */ float4 light_color_pad; + /* 32 */ float4 light_position_base; + /* 48 */ float height; + /* 52 */ float light_intensity; + /* 56 */ float vertical_gradient; + /* 60 */ float opacity; + /* 64 */ float fade; + /* 68 */ float from_scale; + /* 72 */ float to_scale; + /* 76 */ float pad2; + /* 80 */ +}; +static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "wrong size"); + +enum { + idFillExtrusionDrawableUBO = globalUBOCount, + idFillExtrusionTilePropsUBO, + idFillExtrusionPropsUBO, + fillExtrusionUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "FillExtrusionShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"( struct VertexStage { - short2 pos [[attribute(5)]]; - short4 normal_ed [[attribute(6)]]; + short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; + short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]]; #if !defined(HAS_UNIFORM_u_color) - float4 color [[attribute(7)]]; + float4 color [[attribute(fillExtrusionUBOCount + 2)]]; #endif #if !defined(HAS_UNIFORM_u_base) - float base [[attribute(8)]]; + float base [[attribute(fillExtrusionUBOCount + 3)]]; #endif #if !defined(HAS_UNIFORM_u_height) - float height [[attribute(9)]]; + float height [[attribute(fillExtrusionUBOCount + 4)]]; #endif }; @@ -46,19 +101,21 @@ struct FragmentOutput { }; FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const FillExtrusionDrawableUBO& drawable [[buffer(1)]], - device const FillExtrusionInterpolateUBO& interp [[buffer(3)]], - device const FillExtrusionPropsUBO& props [[buffer(4)]]) { + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillExtrusionDrawableUBO* drawableVector [[buffer(idFillExtrusionDrawableUBO)]], + device const FillExtrusionPropsUBO& props [[buffer(idFillExtrusionPropsUBO)]]) { + + device const FillExtrusionDrawableUBO& drawable = drawableVector[uboIndex]; #if defined(HAS_UNIFORM_u_base) const auto base = props.light_position_base.w; #else - const auto base = max(unpack_mix_float(vertx.base, interp.base_t), 0.0); + const auto base = max(unpack_mix_float(vertx.base, drawable.base_t), 0.0); #endif #if defined(HAS_UNIFORM_u_height) const auto height = props.height; #else - const auto height = max(unpack_mix_float(vertx.height, interp.height_t), 0.0); + const auto height = max(unpack_mix_float(vertx.height, drawable.height_t), 0.0); #endif const float3 normal = float3(vertx.normal_ed.xyz); @@ -76,7 +133,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], #if defined(HAS_UNIFORM_u_color) auto color = props.color; #else - auto color = unpack_mix_color(vertx.color, interp.color_t); + auto color = unpack_mix_color(vertx.color, drawable.color_t); #endif // Relative luminance (how dark/bright is the surface color?) @@ -126,5 +183,190 @@ fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]]) { )"; }; +template <> +struct ShaderSource { + static constexpr auto name = "FillExtrusionPatternShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = FILL_EXTRUSION_SHADER_COMMON R"( +struct VertexStage { + short2 pos [[attribute(fillExtrusionUBOCount + 0)]]; + short4 normal_ed [[attribute(fillExtrusionUBOCount + 1)]]; + +#if !defined(HAS_UNIFORM_u_base) + float base [[attribute(fillExtrusionUBOCount + 2)]]; +#endif +#if !defined(HAS_UNIFORM_u_height) + float height [[attribute(fillExtrusionUBOCount + 3)]]; +#endif +#if !defined(HAS_UNIFORM_u_pattern_from) + ushort4 pattern_from [[attribute(fillExtrusionUBOCount + 4)]]; +#endif +#if !defined(HAS_UNIFORM_u_pattern_to) + ushort4 pattern_to [[attribute(fillExtrusionUBOCount + 5)]]; +#endif +}; + +struct FragmentStage { + float4 position [[position, invariant]]; + float4 lighting; + float2 pos_a; + float2 pos_b; + +#if !defined(HAS_UNIFORM_u_pattern_from) + half4 pattern_from; +#endif +#if !defined(HAS_UNIFORM_u_pattern_to) + half4 pattern_to; +#endif +}; + +struct FragmentOutput { + half4 color [[color(0)]]; + //float depth [[depth(less)]]; // Write depth value if it's less than what's already there +}; + +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillExtrusionDrawableUBO* drawableVector [[buffer(idFillExtrusionDrawableUBO)]], + device const FillExtrusionTilePropsUBO* tilePropsVector [[buffer(idFillExtrusionTilePropsUBO)]], + device const FillExtrusionPropsUBO& props [[buffer(idFillExtrusionPropsUBO)]]) { + + device const FillExtrusionDrawableUBO& drawable = drawableVector[uboIndex]; + device const FillExtrusionTilePropsUBO& tileProps = tilePropsVector[uboIndex]; + +#if defined(HAS_UNIFORM_u_base) + const auto base = props.light_position_base.w; +#else + const auto base = max(unpack_mix_float(vertx.base, drawable.base_t), 0.0); +#endif +#if defined(HAS_UNIFORM_u_height) + const auto height = props.height; +#else + const auto height = max(unpack_mix_float(vertx.height, drawable.height_t), 0.0); +#endif + + const float3 normal = float3(vertx.normal_ed.xyz); + const float edgedistance = vertx.normal_ed.w; + const float t = glMod(normal.x, 2.0); + const float z = (t != 0.0) ? height : base; // TODO: This would come out wrong on GL for negative values, check it... + const float4 position = drawable.matrix * float4(float2(vertx.pos), z, 1); + +#if defined(OVERDRAW_INSPECTOR) + return { + .position = position, + .lighting = float4(1.0), + .pattern_from = float4(1.0), + .pattern_to = float4(1.0), + .pos_a = float2(1.0), + .pos_b = float2(1.0), + }; +#endif + +#if defined(HAS_UNIFORM_u_pattern_from) + const auto pattern_from = tileProps.pattern_from; +#else + const auto pattern_from = float4(vertx.pattern_from); +#endif +#if defined(HAS_UNIFORM_u_pattern_to) + const auto pattern_to = tileProps.pattern_to; +#else + const auto pattern_to = float4(vertx.pattern_to); +#endif + + const float2 pattern_tl_a = pattern_from.xy; + const float2 pattern_br_a = pattern_from.zw; + const float2 pattern_tl_b = pattern_to.xy; + const float2 pattern_br_b = pattern_to.zw; + + const float pixelRatio = paintParams.pixel_ratio; + const float tileZoomRatio = drawable.tile_ratio; + const float fromScale = props.from_scale; + const float toScale = props.to_scale; + + const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); + const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); + + const float2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0 + ? float2(vertx.pos) // extrusion top + : float2(edgedistance, z * drawable.height_factor); // extrusion side + + float4 lighting = float4(0.0, 0.0, 0.0, 1.0); + float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0); + directional = mix((1.0 - props.light_intensity), max((0.5 + props.light_intensity), 1.0), directional); + + if (normal.y != 0.0) { + // This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient, + // and otherwise calculates the gradient based on base + height + directional *= ( + (1.0 - props.vertical_gradient) + + (props.vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - props.light_intensity), 1.0))); + } + + lighting.rgb += clamp(directional * props.light_color_pad.rgb, mix(float3(0.0), float3(0.3), 1.0 - props.light_color_pad.rgb), float3(1.0)); + lighting *= props.opacity; + + return { + .position = position, + .lighting = lighting, +#if !defined(HAS_UNIFORM_u_pattern_from) + .pattern_from = half4(pattern_from), +#endif +#if !defined(HAS_UNIFORM_u_pattern_from) + .pattern_to = half4(pattern_to), +#endif + .pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos), + .pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos), + }; +} + +fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const FillExtrusionTilePropsUBO* tilePropsVector [[buffer(idFillExtrusionTilePropsUBO)]], + device const FillExtrusionPropsUBO& props [[buffer(idFillExtrusionPropsUBO)]], + texture2d image0 [[texture(0)]], + sampler image0_sampler [[sampler(0)]]) { +#if defined(OVERDRAW_INSPECTOR) + return {half4(1.0)/*, in.position.z*/}; +#endif + + device const FillExtrusionTilePropsUBO& tileProps = tilePropsVector[uboIndex]; + +#if defined(HAS_UNIFORM_u_pattern_from) + const auto pattern_from = float4(tileProps.pattern_from); +#else + const auto pattern_from = float4(in.pattern_from); +#endif +#if defined(HAS_UNIFORM_u_pattern_to) + const auto pattern_to = float4(tileProps.pattern_to); +#else + const auto pattern_to = float4(in.pattern_to); +#endif + + const float2 pattern_tl_a = pattern_from.xy; + const float2 pattern_br_a = pattern_from.zw; + const float2 pattern_tl_b = pattern_to.xy; + const float2 pattern_br_b = pattern_to.zw; + + const float2 imagecoord = glMod(in.pos_a, 1.0); + const float2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord); + const float4 color1 = image0.sample(image0_sampler, pos); + + const float2 imagecoord_b = glMod(in.pos_b, 1.0); + const float2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b); + const float4 color2 = image0.sample(image0_sampler, pos2); + + return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/}; +} +)"; +}; + } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp b/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp deleted file mode 100644 index 1f3de407bec..00000000000 --- a/include/mbgl/shaders/mtl/fill_extrusion_pattern.hpp +++ /dev/null @@ -1,192 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr auto name = "FillExtrusionPatternShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = R"( -struct VertexStage { - short2 pos [[attribute(5)]]; - short4 normal_ed [[attribute(6)]]; - -#if !defined(HAS_UNIFORM_u_base) - float base [[attribute(7)]]; -#endif -#if !defined(HAS_UNIFORM_u_height) - float height [[attribute(8)]]; -#endif -#if !defined(HAS_UNIFORM_u_pattern_from) - ushort4 pattern_from [[attribute(9)]]; -#endif -#if !defined(HAS_UNIFORM_u_pattern_to) - ushort4 pattern_to [[attribute(10)]]; -#endif -}; - -struct FragmentStage { - float4 position [[position, invariant]]; - float4 lighting; - float2 pos_a; - float2 pos_b; - -#if !defined(HAS_UNIFORM_u_pattern_from) - half4 pattern_from; -#endif -#if !defined(HAS_UNIFORM_u_pattern_to) - half4 pattern_to; -#endif -}; - -struct FragmentOutput { - half4 color [[color(0)]]; - //float depth [[depth(less)]]; // Write depth value if it's less than what's already there -}; - -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const FillExtrusionDrawableUBO& drawable [[buffer(1)]], - device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]], - device const FillExtrusionInterpolateUBO& interp [[buffer(3)]], - device const FillExtrusionPropsUBO& props [[buffer(4)]]) { - -#if defined(HAS_UNIFORM_u_base) - const auto base = props.light_position_base.w; -#else - const auto base = max(unpack_mix_float(vertx.base, interp.base_t), 0.0); -#endif -#if defined(HAS_UNIFORM_u_height) - const auto height = props.height; -#else - const auto height = max(unpack_mix_float(vertx.height, interp.height_t), 0.0); -#endif - - const float3 normal = float3(vertx.normal_ed.xyz); - const float edgedistance = vertx.normal_ed.w; - const float t = glMod(normal.x, 2.0); - const float z = (t != 0.0) ? height : base; // TODO: This would come out wrong on GL for negative values, check it... - const float4 position = drawable.matrix * float4(float2(vertx.pos), z, 1); - -#if defined(OVERDRAW_INSPECTOR) - return { - .position = position, - .lighting = float4(1.0), - .pattern_from = float4(1.0), - .pattern_to = float4(1.0), - .pos_a = float2(1.0), - .pos_b = float2(1.0), - }; -#endif - -#if defined(HAS_UNIFORM_u_pattern_from) - const auto pattern_from = tileProps.pattern_from; -#else - const auto pattern_from = float4(vertx.pattern_from); -#endif -#if defined(HAS_UNIFORM_u_pattern_to) - const auto pattern_to = tileProps.pattern_to; -#else - const auto pattern_to = float4(vertx.pattern_to); -#endif - - const float2 pattern_tl_a = pattern_from.xy; - const float2 pattern_br_a = pattern_from.zw; - const float2 pattern_tl_b = pattern_to.xy; - const float2 pattern_br_b = pattern_to.zw; - - const float pixelRatio = paintParams.pixel_ratio; - const float tileZoomRatio = drawable.tile_ratio; - const float fromScale = props.from_scale; - const float toScale = props.to_scale; - - const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); - const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); - - const float2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0 - ? float2(vertx.pos) // extrusion top - : float2(edgedistance, z * drawable.height_factor); // extrusion side - - float4 lighting = float4(0.0, 0.0, 0.0, 1.0); - float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0); - directional = mix((1.0 - props.light_intensity), max((0.5 + props.light_intensity), 1.0), directional); - - if (normal.y != 0.0) { - // This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient, - // and otherwise calculates the gradient based on base + height - directional *= ( - (1.0 - props.vertical_gradient) + - (props.vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - props.light_intensity), 1.0))); - } - - lighting.rgb += clamp(directional * props.light_color_pad.rgb, mix(float3(0.0), float3(0.3), 1.0 - props.light_color_pad.rgb), float3(1.0)); - lighting *= props.opacity; - - return { - .position = position, - .lighting = lighting, -#if !defined(HAS_UNIFORM_u_pattern_from) - .pattern_from = half4(pattern_from), -#endif -#if !defined(HAS_UNIFORM_u_pattern_from) - .pattern_to = half4(pattern_to), -#endif - .pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos), - .pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos), - }; -} - -fragment FragmentOutput fragmentMain(FragmentStage in [[stage_in]], - device const FillExtrusionDrawableUBO& drawable [[buffer(1)]], - device const FillExtrusionTilePropsUBO& tileProps [[buffer(2)]], - device const FillExtrusionPropsUBO& props [[buffer(4)]], - texture2d image0 [[texture(0)]], - sampler image0_sampler [[sampler(0)]]) { -#if defined(OVERDRAW_INSPECTOR) - return {half4(1.0)/*, in.position.z*/}; -#endif - -#if defined(HAS_UNIFORM_u_pattern_from) - const auto pattern_from = float4(tileProps.pattern_from); -#else - const auto pattern_from = float4(in.pattern_from); -#endif -#if defined(HAS_UNIFORM_u_pattern_to) - const auto pattern_to = float4(tileProps.pattern_to); -#else - const auto pattern_to = float4(in.pattern_to); -#endif - - const float2 pattern_tl_a = pattern_from.xy; - const float2 pattern_br_a = pattern_from.zw; - const float2 pattern_tl_b = pattern_to.xy; - const float2 pattern_br_b = pattern_to.zw; - - const float2 imagecoord = glMod(in.pos_a, 1.0); - const float2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord); - const float4 color1 = image0.sample(image0_sampler, pos); - - const float2 imagecoord_b = glMod(in.pos_b, 1.0); - const float2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b); - const float4 color2 = image0.sample(image0_sampler, pos2); - - return {half4(mix(color1, color2, props.fade) * in.lighting)/*, in.position.z*/}; -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/heatmap.hpp b/include/mbgl/shaders/mtl/heatmap.hpp index e04ae35d126..1d0a3fa8034 100644 --- a/include/mbgl/shaders/mtl/heatmap.hpp +++ b/include/mbgl/shaders/mtl/heatmap.hpp @@ -2,33 +2,64 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define HEATMAP_SHADER_PRELUDE R"( + +struct alignas(16) HeatmapDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float extrude_scale; + + // Interpolations + /* 68 */ float weight_t; + /* 72 */ float radius_t; + /* 76 */ float pad1; + /* 80 */ +}; +static_assert(sizeof(HeatmapDrawableUBO) == 5 * 16, "wrong size"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) HeatmapEvaluatedPropsUBO { + /* 0 */ float weight; + /* 4 */ float radius; + /* 8 */ float intensity; + /* 12 */ float padding; + /* 16 */ +}; +static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16, "wrong size"); + +enum { + idHeatmapDrawableUBO = globalUBOCount, + idHeatmapEvaluatedPropsUBO, + heatmapUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "HeatmapShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = HEATMAP_SHADER_PRELUDE R"( struct VertexStage { - short2 pos [[attribute(4)]]; + short2 pos [[attribute(heatmapUBOCount + 0)]]; #if !defined(HAS_UNIFORM_u_weight) - float2 weight [[attribute(5)]]; + float2 weight [[attribute(heatmapUBOCount + 1)]]; #endif #if !defined(HAS_UNIFORM_u_radius) - float2 radius [[attribute(6)]]; + float2 radius [[attribute(heatmapUBOCount + 2)]]; #endif }; @@ -38,26 +69,6 @@ struct FragmentStage { float2 extrude; }; -struct alignas(16) HeatmapDrawableUBO { - float4x4 matrix; - float extrude_scale; - float pad1; - float2 pad2; -}; - -struct alignas(16) HeatmapEvaluatedPropsUBO { - float weight; - float radius; - float intensity; - float pad1; -}; - -struct alignas(16) HeatmapInterpolateUBO { - float weight_t; - float radius_t; - float2 pad1; -}; - // Effective "0" in the kernel density texture to adjust the kernel size to; // this empirically chosen number minimizes artifacts on overlapping kernels // for typical heatmap cases (assuming clustered source) @@ -67,19 +78,21 @@ constant const float ZERO = 1.0 / 255.0 / 16.0; #define GAUSS_COEF 0.3989422804014327 FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HeatmapDrawableUBO& drawable [[buffer(1)]], - device const HeatmapInterpolateUBO& interp [[buffer(2)]], - device const HeatmapEvaluatedPropsUBO& props [[buffer(3)]]) { + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const HeatmapDrawableUBO* drawableVector [[buffer(idHeatmapDrawableUBO)]], + device const HeatmapEvaluatedPropsUBO& props [[buffer(idHeatmapEvaluatedPropsUBO)]]) { + + device const HeatmapDrawableUBO& drawable = drawableVector[uboIndex]; #if defined(HAS_UNIFORM_u_weight) const auto weight = props.weight; #else - const auto weight = unpack_mix_float(vertx.weight, interp.weight_t); + const auto weight = unpack_mix_float(vertx.weight, drawable.weight_t); #endif #if defined(HAS_UNIFORM_u_radius) const auto radius = props.radius; #else - const auto radius = unpack_mix_float(vertx.radius, interp.radius_t); + const auto radius = unpack_mix_float(vertx.radius, drawable.radius_t); #endif // unencode the extrusion vector that we snuck into the a_pos vector @@ -117,7 +130,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HeatmapEvaluatedPropsUBO& props [[buffer(3)]]) { + device const HeatmapEvaluatedPropsUBO& props [[buffer(idHeatmapEvaluatedPropsUBO)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index 0406676c552..6745492e102 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -2,12 +2,30 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define HEATMAP_TEXTURE_SHADER_PRELUDE R"( + +struct alignas(16) HeatmapTexturePropsUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float opacity; + /* 68 */ float pad1; + /* 72 */ float pad2; + /* 76 */ float pad3; + /* 80 */ +}; +static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16, "wrong size"); + +enum { + idHeatmapTexturePropsUBO = globalUBOCount, + heatmapTextureUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "HeatmapTextureShader"; @@ -19,10 +37,10 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = HEATMAP_TEXTURE_SHADER_PRELUDE R"( struct VertexStage { - short2 pos [[attribute(2)]]; + short2 pos [[attribute(heatmapTextureUBOCount + 0)]]; }; struct FragmentStage { @@ -30,15 +48,9 @@ struct FragmentStage { float2 pos; }; -struct alignas(16) HeatmapTexturePropsUBO { - float4x4 matrix; - float opacity; - float pad1, pad2, pad3; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const HeatmapTexturePropsUBO& props [[buffer(1)]]) { + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const HeatmapTexturePropsUBO& props [[buffer(idHeatmapTexturePropsUBO)]]) { const float2 pos = float2(vertx.pos); const float4 position = props.matrix * float4(pos * paintParams.world_size, 0, 1); @@ -50,7 +62,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HeatmapTexturePropsUBO& props [[buffer(1)]], + device const HeatmapTexturePropsUBO& props [[buffer(idHeatmapTexturePropsUBO)]], texture2d image [[texture(0)]], texture2d color_ramp [[texture(1)]], sampler image_sampler [[sampler(0)]], diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index 612954d9412..35005696673 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -2,28 +2,60 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define HILLSHADE_SHADER_PRELUDE R"( + +struct alignas(16) HillshadeDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ +}; +static_assert(sizeof(HillshadeDrawableUBO) == 4 * 16, "wrong size"); + +struct alignas(16) HillshadeTilePropsUBO { + /* 0 */ float2 latrange; + /* 8 */ float2 light; + /* 16 */ +}; +static_assert(sizeof(HillshadeTilePropsUBO) == 16, "wrong size"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) HillshadeEvaluatedPropsUBO { + /* 0 */ float4 highlight; + /* 16 */ float4 shadow; + /* 32 */ float4 accent; + /* 48 */ +}; +static_assert(sizeof(HillshadeEvaluatedPropsUBO) == 3 * 16, "wrong size"); + +enum { + idHillshadeDrawableUBO = globalUBOCount, + idHillshadeTilePropsUBO, + idHillshadeEvaluatedPropsUBO, + hillshadeUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "HillshadeShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = HILLSHADE_SHADER_PRELUDE R"( struct VertexStage { - short2 pos [[attribute(3)]]; - short2 texture_pos [[attribute(4)]]; + short2 pos [[attribute(hillshadeUBOCount + 0)]]; + short2 texture_pos [[attribute(hillshadeUBOCount + 1)]]; }; struct FragmentStage { @@ -31,21 +63,12 @@ struct FragmentStage { float2 pos; }; -struct alignas(16) HillshadeDrawableUBO { - float4x4 matrix; - float2 latrange; - float2 light; -}; - -struct alignas(16) HillshadeEvaluatedPropsUBO { - float4 highlight; - float4 shadow; - float4 accent; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HillshadeDrawableUBO& drawable [[buffer(1)]]) { + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const HillshadeDrawableUBO* drawableVector [[buffer(idHillshadeDrawableUBO)]]) { + device const HillshadeDrawableUBO& drawable = drawableVector[uboIndex]; + const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); float2 pos = float2(vertx.texture_pos) / 8192.0; pos.y = 1.0 - pos.y; @@ -57,30 +80,33 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HillshadeDrawableUBO& drawable [[buffer(1)]], - device const HillshadeEvaluatedPropsUBO& props [[buffer(2)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const HillshadeTilePropsUBO* tilePropsVector [[buffer(idHillshadeTilePropsUBO)]], + device const HillshadeEvaluatedPropsUBO& props [[buffer(idHillshadeEvaluatedPropsUBO)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif + device const HillshadeTilePropsUBO& tileProps = tilePropsVector[uboIndex]; + float4 pixel = image.sample(image_sampler, in.pos); float2 deriv = ((pixel.rg * 2.0) - 1.0); // We divide the slope by a scale factor based on the cosin of the pixel's approximate latitude // to account for mercator projection distortion. see #4807 for details - float scaleFactor = cos(radians((drawable.latrange[0] - drawable.latrange[1]) * in.pos.y + drawable.latrange[1])); + float scaleFactor = cos(radians((tileProps.latrange[0] - tileProps.latrange[1]) * in.pos.y + tileProps.latrange[1])); // We also multiply the slope by an arbitrary z-factor of 1.25 float slope = atan(1.25 * length(deriv) / scaleFactor); float aspect = deriv.x != 0.0 ? atan2(deriv.y, -deriv.x) : M_PI_F / 2.0 * (deriv.y > 0.0 ? 1.0 : -1.0); - float intensity = drawable.light.x; + float intensity = tileProps.light.x; // We add PI to make this property match the global light object, which adds PI/2 to the light's azimuthal // position property to account for 0deg corresponding to north/the top of the viewport in the style spec // and the original shader was written to accept (-illuminationDirection - 90) as the azimuthal. - float azimuth = drawable.light.y + M_PI_F; + float azimuth = tileProps.light.y + M_PI_F; // We scale the slope exponentially based on intensity, using a calculation similar to // the exponential interpolation function in the style spec: diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index 6a74245ffd4..b2c0b7522da 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -2,27 +2,51 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define HILLSHADE_PREPARE_SHADER_PRELUDE R"( + +struct alignas(16) HillshadePrepareDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ +}; +static_assert(sizeof(HillshadePrepareDrawableUBO) == 4 * 16, "wrong size"); + +struct alignas(16) HillshadePrepareTilePropsUBO { + /* 0 */ float4 unpack; + /* 16 */ float2 dimension; + /* 24 */ float zoom; + /* 28 */ float maxzoom; + /* 32 */ +}; +static_assert(sizeof(HillshadePrepareTilePropsUBO) == 2 * 16, "wrong size"); + +enum { + idHillshadePrepareDrawableUBO = globalUBOCount, + idHillshadePrepareTilePropsUBO, + hillshadePrepareUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "HillshadePrepareShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = HILLSHADE_PREPARE_SHADER_PRELUDE R"( struct VertexStage { - short2 pos [[attribute(2)]]; - short2 texture_pos [[attribute(3)]]; + short2 pos [[attribute(hillshadePrepareUBOCount + 0)]]; + short2 texture_pos [[attribute(hillshadePrepareUBOCount + 1)]]; }; struct FragmentStage { @@ -30,21 +54,14 @@ struct FragmentStage { float2 pos; }; -struct alignas(16) HillshadePrepareDrawableUBO { - float4x4 matrix; - float4 unpack; - float2 dimension; - float zoom; - float maxzoom; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const HillshadePrepareDrawableUBO& drawable [[buffer(1)]]) { + device const HillshadePrepareDrawableUBO& drawable [[buffer(idHillshadePrepareDrawableUBO)]], + device const HillshadePrepareTilePropsUBO& tileProps [[buffer(idHillshadePrepareTilePropsUBO)]]) { const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); - float2 epsilon = 1.0 / drawable.dimension; - float scale = (drawable.dimension.x - 2.0) / drawable.dimension.x; + float2 epsilon = 1.0 / tileProps.dimension; + float scale = (tileProps.dimension.x - 2.0) / tileProps.dimension.x; const float2 pos = (float2(vertx.texture_pos) / 8192.0) * scale + epsilon; return { @@ -61,14 +78,14 @@ float getElevation(float2 coord, float bias, texture2d im } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const HillshadePrepareDrawableUBO& drawable [[buffer(1)]], + device const HillshadePrepareTilePropsUBO& tileProps [[buffer(idHillshadePrepareTilePropsUBO)]], texture2d image [[texture(0)]], sampler image_sampler [[sampler(0)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif - float2 epsilon = 1.0 / drawable.dimension; + float2 epsilon = 1.0 / tileProps.dimension; // queried pixels: // +-----------+ @@ -85,15 +102,15 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], // | | | | // +-----------+ - float a = getElevation(in.pos + float2(-epsilon.x, -epsilon.y), 0.0, image, image_sampler, drawable.unpack); - float b = getElevation(in.pos + float2(0, -epsilon.y), 0.0, image, image_sampler, drawable.unpack); - float c = getElevation(in.pos + float2(epsilon.x, -epsilon.y), 0.0, image, image_sampler, drawable.unpack); - float d = getElevation(in.pos + float2(-epsilon.x, 0), 0.0, image, image_sampler, drawable.unpack); - //float e = getElevation(in.pos, 0.0, image, image_sampler, drawable.unpack); - float f = getElevation(in.pos + float2(epsilon.x, 0), 0.0, image, image_sampler, drawable.unpack); - float g = getElevation(in.pos + float2(-epsilon.x, epsilon.y), 0.0, image, image_sampler, drawable.unpack); - float h = getElevation(in.pos + float2(0, epsilon.y), 0.0, image, image_sampler, drawable.unpack); - float i = getElevation(in.pos + float2(epsilon.x, epsilon.y), 0.0, image, image_sampler, drawable.unpack); + float a = getElevation(in.pos + float2(-epsilon.x, -epsilon.y), 0.0, image, image_sampler, tileProps.unpack); + float b = getElevation(in.pos + float2(0, -epsilon.y), 0.0, image, image_sampler, tileProps.unpack); + float c = getElevation(in.pos + float2(epsilon.x, -epsilon.y), 0.0, image, image_sampler, tileProps.unpack); + float d = getElevation(in.pos + float2(-epsilon.x, 0), 0.0, image, image_sampler, tileProps.unpack); + //float e = getElevation(in.pos, 0.0, image, image_sampler, tileProps.unpack); + float f = getElevation(in.pos + float2(epsilon.x, 0), 0.0, image, image_sampler, tileProps.unpack); + float g = getElevation(in.pos + float2(-epsilon.x, epsilon.y), 0.0, image, image_sampler, tileProps.unpack); + float h = getElevation(in.pos + float2(0, epsilon.y), 0.0, image, image_sampler, tileProps.unpack); + float i = getElevation(in.pos + float2(epsilon.x, epsilon.y), 0.0, image, image_sampler, tileProps.unpack); // here we divide the x and y slopes by 8 * pixel size // where pixel size (aka meters/pixel) is: @@ -106,12 +123,12 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], // Here we use a=0.3 which works out to the expression below. see // nickidlugash's awesome breakdown for more info // https://github.com/mapbox/mapbox-gl-js/pull/5286#discussion_r148419556 - float exaggeration = drawable.zoom < 2.0 ? 0.4 : drawable.zoom < 4.5 ? 0.35 : 0.3; + float exaggeration = tileProps.zoom < 2.0 ? 0.4 : tileProps.zoom < 4.5 ? 0.35 : 0.3; float2 deriv = float2( (c + f + f + i) - (a + d + d + g), (g + h + h + i) - (a + b + b + c) - ) / pow(2.0, (drawable.zoom - drawable.maxzoom) * exaggeration + 19.2562 - drawable.zoom); + ) / pow(2.0, (tileProps.zoom - tileProps.maxzoom) * exaggeration + 19.2562 - tileProps.zoom); float4 color = clamp(float4( deriv.x / 2.0 + 0.5, diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index fd377413c5a..f771a2caf05 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -2,24 +2,188 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define LINE_SHADER_COMMON R"( + +// +// Line + +struct alignas(16) LineDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float ratio; + + // Interpolations + /* 68 */ float color_t; + /* 72 */ float blur_t; + /* 76 */ float opacity_t; + /* 80 */ float gapwidth_t; + /* 84 */ float offset_t; + /* 88 */ float width_t; + /* 92 */ float pad1; + /* 96 */ +}; +static_assert(sizeof(LineDrawableUBO) == 6 * 16, "wrong size"); + +// +// Line gradient + +struct alignas(16) LineGradientDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float ratio; + + // Interpolations + /* 68 */ float blur_t; + /* 72 */ float opacity_t; + /* 76 */ float gapwidth_t; + /* 80 */ float offset_t; + /* 84 */ float width_t; + /* 88 */ float pad1; + /* 92 */ float pad2; + /* 96 */ +}; +static_assert(sizeof(LineGradientDrawableUBO) == 6 * 16, "wrong size"); + +// +// Line pattern + +struct alignas(16) LinePatternDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float ratio; + + // Interpolations + /* 68 */ float blur_t; + /* 72 */ float opacity_t; + /* 76 */ float gapwidth_t; + /* 80 */ float offset_t; + /* 84 */ float width_t; + /* 88 */ float pattern_from_t; + /* 92 */ float pattern_to_t; + /* 96 */ +}; +static_assert(sizeof(LinePatternDrawableUBO) == 6 * 16, "wrong size"); + +struct alignas(16) LinePatternTilePropsUBO { + /* 0 */ float4 pattern_from; + /* 16 */ float4 pattern_to; + /* 32 */ float4 scale; + /* 48 */ float2 texsize; + /* 56 */ float fade; + /* 60 */ float pad2; + /* 64 */ +}; +static_assert(sizeof(LinePatternTilePropsUBO) == 4 * 16, "wrong size"); + +// +// Line SDF + +struct alignas(16) LineSDFDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float2 patternscale_a; + /* 72 */ float2 patternscale_b; + /* 80 */ float tex_y_a; + /* 84 */ float tex_y_b; + /* 88 */ float ratio; + + // Interpolations + /* 92 */ float color_t; + /* 96 */ float blur_t; + /* 100 */ float opacity_t; + /* 104 */ float gapwidth_t; + /* 108 */ float offset_t; + /* 112 */ float width_t; + /* 116 */ float floorwidth_t; + /* 120 */ float pad1; + /* 124 */ float pad2; + /* 128 */ +}; +static_assert(sizeof(LineSDFDrawableUBO) == 8 * 16, "wrong size"); + +struct alignas(16) LineSDFTilePropsUBO { + /* 0 */ float sdfgamma; + /* 4 */ float mix; + /* 8 */ float pad1; + /* 12 */ float pad2; + /* 16 */ +}; +static_assert(sizeof(LineSDFTilePropsUBO) == 16, "wrong size"); + +/// Expression properties that do not depend on the tile +enum class LineExpressionMask : uint32_t { + None = 0, + Color = 1 << 0, + Opacity = 1 << 1, + Blur = 1 << 2, + Width = 1 << 3, + GapWidth = 1 << 4, + FloorWidth = 1 << 5, + Offset = 1 << 6, +}; +bool operator&(LineExpressionMask a, LineExpressionMask b) { return (uint32_t)a & (uint32_t)b; } + +struct alignas(16) LineExpressionUBO { + GPUExpression color; + GPUExpression blur; + GPUExpression opacity; + GPUExpression gapwidth; + GPUExpression offset; + GPUExpression width; + GPUExpression floorwidth; +}; +static_assert(sizeof(LineExpressionUBO) % 16 == 0, "wrong alignment"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) LineEvaluatedPropsUBO { + /* 0 */ float4 color; + /* 16 */ float blur; + /* 20 */ float opacity; + /* 24 */ float gapwidth; + /* 28 */ float offset; + /* 32 */ float width; + /* 36 */ float floorwidth; + /* 40 */ LineExpressionMask expressionMask; + /* 44 */ float pad1; + /* 48 */ +}; +static_assert(sizeof(LineEvaluatedPropsUBO) == 3 * 16, "wrong size"); + +union LineDrawableUnionUBO { + LineDrawableUBO lineDrawableUBO; + LineGradientDrawableUBO lineGradientDrawableUBO; + LinePatternDrawableUBO linePatternDrawableUBO; + LineSDFDrawableUBO lineSDFDrawableUBO; +}; + +union LineTilePropsUnionUBO { + LinePatternTilePropsUBO linePatternTilePropsUBO; + LineSDFTilePropsUBO lineSDFTilePropsUBO; +}; + +enum { + idLineDrawableUBO = globalUBOCount, + idLineTilePropsUBO, + idLineEvaluatedPropsUBO, + idLineExpressionUBO, + lineUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "LineShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = LINE_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -61,48 +225,34 @@ struct FragmentStage { #endif }; -struct alignas(16) LineDrawableUBO { - float4x4 matrix; - float ratio; - float pad1, pad2, pad3; -}; - -struct alignas(16) LineInterpolationUBO { - float color_t; - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float pad1, pad2; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], - device const LineDrawableUBO& drawable [[buffer(idLineDrawableUBO)]], - device const LineInterpolationUBO& interp [[buffer(idLineInterpolationUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const LineDrawableUnionUBO* drawableVector [[buffer(idLineDrawableUBO)]], device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]], device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]]) { + device const LineDrawableUBO& drawable = drawableVector[uboIndex].lineDrawableUBO; + #if defined(HAS_UNIFORM_u_gapwidth) const auto exprGapWidth = (props.expressionMask & LineExpressionMask::GapWidth); - const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.zoom) : props.gapwidth) / 2; + const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.map_zoom) : props.gapwidth) / 2; #else - const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2; + const auto gapwidth = unpack_mix_float(vertx.gapwidth, drawable.gapwidth_t) / 2; #endif #if defined(HAS_UNIFORM_u_offset) const auto exprOffset = (props.expressionMask & LineExpressionMask::Offset); - const auto offset = (exprOffset ? expr.offset.eval(paintParams.zoom) : props.offset) * -1; + const auto offset = (exprOffset ? expr.offset.eval(paintParams.map_zoom) : props.offset) * -1; #else - const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1; + const auto offset = unpack_mix_float(vertx.offset, drawable.offset_t) * -1; #endif #if defined(HAS_UNIFORM_u_width) const auto exprWidth = (props.expressionMask & LineExpressionMask::Width); - const auto width = exprWidth ? expr.width.eval(paintParams.zoom) : props.width; + const auto width = exprWidth ? expr.width.eval(paintParams.map_zoom) : props.width; #else - const auto width = unpack_mix_float(vertx.width, interp.width_t); + const auto width = unpack_mix_float(vertx.width, drawable.width_t); #endif // the distance over which the line edge fades out. @@ -148,13 +298,13 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], .gamma_scale = half(extrude_length_without_perspective / extrude_length_with_perspective), #if !defined(HAS_UNIFORM_u_color) - .color = unpack_mix_color(vertx.color, interp.color_t), + .color = unpack_mix_color(vertx.color, drawable.color_t), #endif #if !defined(HAS_UNIFORM_u_blur) - .blur = unpack_mix_float(vertx.blur, interp.blur_t), + .blur = unpack_mix_float(vertx.blur, drawable.blur_t), #endif #if !defined(HAS_UNIFORM_u_opacity) - .opacity = unpack_mix_float(vertx.opacity, interp.opacity_t), + .opacity = unpack_mix_float(vertx.opacity, drawable.opacity_t), #endif }; } @@ -169,21 +319,21 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], #if defined(HAS_UNIFORM_u_color) const auto exprColor = (props.expressionMask & LineExpressionMask::Color); - const auto color = exprColor ? expr.color.evalColor(paintParams.zoom) : props.color; + const auto color = exprColor ? expr.color.evalColor(paintParams.map_zoom) : props.color; #else const float4 color = in.color; #endif #if defined(HAS_UNIFORM_u_blur) const auto exprBlur = (props.expressionMask & LineExpressionMask::Blur); - const float blur = exprBlur ? expr.blur.eval(paintParams.zoom) : props.blur; + const float blur = exprBlur ? expr.blur.eval(paintParams.map_zoom) : props.blur; #else const float blur = in.blur; #endif #if defined(HAS_UNIFORM_u_opacity) const auto exprOpacity = (props.expressionMask & LineExpressionMask::Opacity); - const float opacity = exprOpacity ? expr.opacity.eval(paintParams.zoom) : props.opacity; + const float opacity = exprOpacity ? expr.opacity.eval(paintParams.map_zoom) : props.opacity; #else const float opacity = in.opacity; #endif @@ -207,12 +357,12 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = LINE_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -248,48 +398,34 @@ struct FragmentStage { #endif }; -struct alignas(16) LineGradientDrawableUBO { - float4x4 matrix; - float ratio; - float pad1, pad2, pad3; -}; - -struct alignas(16) LineGradientInterpolationUBO { - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float pad1, pad2, pad3; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], - device const LineGradientDrawableUBO& drawable [[buffer(idLineDrawableUBO)]], - device const LineGradientInterpolationUBO& interp [[buffer(idLineInterpolationUBO)]], - device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]], - device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]]) { + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const LineDrawableUnionUBO* drawableVector [[buffer(idLineDrawableUBO)]], + device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]]) { + + device const LineGradientDrawableUBO& drawable = drawableVector[uboIndex].lineGradientDrawableUBO; #if !defined(HAS_UNIFORM_u_blur) - const auto blur = unpack_mix_float(vertx.blur, interp.blur_t); + const auto blur = unpack_mix_float(vertx.blur, drawable.blur_t); #endif #if !defined(HAS_UNIFORM_u_opacity) - const auto opacity = unpack_mix_float(vertx.opacity, interp.opacity_t); + const auto opacity = unpack_mix_float(vertx.opacity, drawable.opacity_t); #endif #if defined(HAS_UNIFORM_u_gapwidth) const auto gapwidth = props.gapwidth / 2; #else - const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2; + const auto gapwidth = unpack_mix_float(vertx.gapwidth, drawable.gapwidth_t) / 2; #endif #if defined(HAS_UNIFORM_u_offset) const auto offset = props.offset * -1; #else - const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1; + const auto offset = unpack_mix_float(vertx.offset, drawable.offset_t) * -1; #endif #if defined(HAS_UNIFORM_u_width) const auto width = props.width; #else - const auto width = unpack_mix_float(vertx.width, interp.width_t); + const auto width = unpack_mix_float(vertx.width, drawable.width_t); #endif // the distance over which the line edge fades out. @@ -347,7 +483,6 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]], device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]], - device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]], texture2d gradientTexture [[texture(0)]]) { #if defined(OVERDRAW_INSPECTOR) return half4(1.0); @@ -388,12 +523,12 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = LINE_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -442,57 +577,34 @@ struct FragmentStage { #endif }; -struct alignas(16) LinePatternDrawableUBO { - float4x4 matrix; - float4 scale; - float2 texsize; - float ratio; - float fade; -}; - -struct alignas(16) LinePatternInterpolationUBO { - float blur_t; - float opacity_t; - float offset_t; - float gapwidth_t; - float width_t; - float pattern_from_t; - float pattern_to_t; - float pad1; -}; - -struct alignas(16) LinePatternTilePropertiesUBO { - float4 pattern_from; - float4 pattern_to; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], - device const LinePatternDrawableUBO& drawable [[buffer(idLineDrawableUBO)]], - device const LinePatternInterpolationUBO& interp [[buffer(idLineInterpolationUBO)]], - device const LinePatternTilePropertiesUBO& tileProps [[buffer(idLineTilePropertiesUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const LineDrawableUnionUBO* drawableVector [[buffer(idLineDrawableUBO)]], device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]], device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]]) { + device const LinePatternDrawableUBO& drawable = drawableVector[uboIndex].linePatternDrawableUBO; + #if defined(HAS_UNIFORM_u_gapwidth) const auto exprGapWidth = (props.expressionMask & LineExpressionMask::GapWidth); - const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.zoom) : props.gapwidth) / 2; + const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.map_zoom) : props.gapwidth) / 2; #else - const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2; + const auto gapwidth = unpack_mix_float(vertx.gapwidth, drawable.gapwidth_t) / 2; #endif #if defined(HAS_UNIFORM_u_offset) const auto exprOffset = (props.expressionMask & LineExpressionMask::Offset); - const auto offset = (exprOffset ? expr.offset.eval(paintParams.zoom) : props.offset) * -1; + const auto offset = (exprOffset ? expr.offset.eval(paintParams.map_zoom) : props.offset) * -1; #else - const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1; + const auto offset = unpack_mix_float(vertx.offset, drawable.offset_t) * -1; #endif #if defined(HAS_UNIFORM_u_width) const auto exprWidth = (props.expressionMask & LineExpressionMask::Width); - const auto width = exprWidth ? expr.width.eval(paintParams.zoom) : props.width; + const auto width = exprWidth ? expr.width.eval(paintParams.map_zoom) : props.width; #else - const auto width = unpack_mix_float(vertx.width, interp.width_t); + const auto width = unpack_mix_float(vertx.width, drawable.width_t); #endif // the distance over which the line edge fades out. @@ -541,10 +653,10 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], .linesofar = linesofar, #if !defined(HAS_UNIFORM_u_blur) - .blur = half(unpack_mix_float(vertx.blur, interp.blur_t)), + .blur = half(unpack_mix_float(vertx.blur, drawable.blur_t)), #endif #if !defined(HAS_UNIFORM_u_opacity) - .opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)), + .opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)), #endif #if !defined(HAS_UNIFORM_u_pattern_from) .pattern_from = half4(vertx.pattern_from), @@ -557,26 +669,29 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]], device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], - device const LinePatternDrawableUBO& drawable [[buffer(idLineDrawableUBO)]], - device const LinePatternTilePropertiesUBO& tileProps [[buffer(idLineTilePropertiesUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const LineTilePropsUnionUBO* tilePropsVector [[buffer(idLineTilePropsUBO)]], device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]], device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { + #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif + device const LinePatternTilePropsUBO& tileProps = tilePropsVector[uboIndex].linePatternTilePropsUBO; + #if defined(HAS_UNIFORM_u_blur) const auto exprBlur = (props.expressionMask & LineExpressionMask::Blur); - const float blur = exprBlur ? expr.blur.eval(paintParams.zoom) : props.blur; + const float blur = exprBlur ? expr.blur.eval(paintParams.map_zoom) : props.blur; #else const float blur = in.blur; #endif #if defined(HAS_UNIFORM_u_opacity) const auto exprOpacity = (props.expressionMask & LineExpressionMask::Opacity); - const float opacity = exprOpacity ? expr.opacity.eval(paintParams.zoom) : props.opacity; + const float opacity = exprOpacity ? expr.opacity.eval(paintParams.map_zoom) : props.opacity; #else const float opacity = in.opacity; #endif @@ -598,10 +713,10 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], const float2 pattern_tl_b = pattern_to.xy; const float2 pattern_br_b = pattern_to.zw; - const float pixelRatio = drawable.scale.x; - const float tileZoomRatio = drawable.scale.y; - const float fromScale = drawable.scale.z; - const float toScale = drawable.scale.w; + const float pixelRatio = tileProps.scale.x; + const float tileZoomRatio = tileProps.scale.y; + const float fromScale = tileProps.scale.z; + const float toScale = tileProps.scale.w; const float2 display_size_a = float2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); const float2 display_size_b = float2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); @@ -628,10 +743,10 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], // the texture coordinate const float y_a = 0.5 + (in.normal.y * clamp(in.width2.x, 0.0, (pattern_size_a.y + 2.0) / 2.0) / pattern_size_a.y); const float y_b = 0.5 + (in.normal.y * clamp(in.width2.x, 0.0, (pattern_size_b.y + 2.0) / 2.0) / pattern_size_b.y); - const float2 pos_a = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, float2(x_a, y_a)); - const float2 pos_b = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, float2(x_b, y_b)); + const float2 pos_a = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, float2(x_a, y_a)); + const float2 pos_b = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, float2(x_b, y_b)); - const float4 color = mix(image0.sample(image0_sampler, pos_a), image0.sample(image0_sampler, pos_b), drawable.fade); + const float4 color = mix(image0.sample(image0_sampler, pos_a), image0.sample(image0_sampler, pos_b), tileProps.fade); return half4(color * alpha * opacity); } @@ -649,7 +764,7 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = LINE_SHADER_COMMON R"( struct VertexStage { short2 pos_normal [[attribute(lineUBOCount + 0)]]; uchar4 data [[attribute(lineUBOCount + 1)]]; @@ -699,62 +814,41 @@ struct FragmentStage { #endif }; -struct alignas(16) LineSDFDrawableUBO { - float4x4 matrix; - float2 patternscale_a; - float2 patternscale_b; - float ratio; - float tex_y_a; - float tex_y_b; - float sdfgamma; - float mix; - float pad1, pad2, pad3; -}; - -struct alignas(16) LineSDFInterpolationUBO { - float color_t; - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float floorwidth_t; - float pad1; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], - device const LineSDFDrawableUBO& drawable [[buffer(idLineDrawableUBO)]], - device const LineSDFInterpolationUBO& interp [[buffer(idLineInterpolationUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const LineDrawableUnionUBO* drawableVector [[buffer(idLineDrawableUBO)]], device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]], device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]]) { + device const LineSDFDrawableUBO& drawable = drawableVector[uboIndex].lineSDFDrawableUBO; + #if defined(HAS_UNIFORM_u_gapwidth) const auto exprGapWidth = (props.expressionMask & LineExpressionMask::GapWidth); - const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.zoom) : props.gapwidth) / 2.0; + const auto gapwidth = (exprGapWidth ? expr.gapwidth.eval(paintParams.map_zoom) : props.gapwidth) / 2.0; #else - const auto gapwidth = unpack_mix_float(vertx.gapwidth, interp.gapwidth_t) / 2.0; + const auto gapwidth = unpack_mix_float(vertx.gapwidth, drawable.gapwidth_t) / 2.0; #endif #if defined(HAS_UNIFORM_u_offset) const auto exprOffset = (props.expressionMask & LineExpressionMask::Offset); - const auto offset = (exprOffset ? expr.offset.eval(paintParams.zoom) : props.offset) * -1.0; + const auto offset = (exprOffset ? expr.offset.eval(paintParams.map_zoom) : props.offset) * -1.0; #else - const auto offset = unpack_mix_float(vertx.offset, interp.offset_t) * -1.0; + const auto offset = unpack_mix_float(vertx.offset, drawable.offset_t) * -1.0; #endif #if defined(HAS_UNIFORM_u_width) const auto exprWidth = (props.expressionMask & LineExpressionMask::Width); - const auto width = exprWidth ? expr.width.eval(paintParams.zoom) : props.width; + const auto width = exprWidth ? expr.width.eval(paintParams.map_zoom) : props.width; #else - const auto width = unpack_mix_float(vertx.width, interp.width_t); + const auto width = unpack_mix_float(vertx.width, drawable.width_t); #endif #if defined(HAS_UNIFORM_u_floorwidth) const auto exprFloorWidth = (props.expressionMask & LineExpressionMask::FloorWidth); - const auto floorwidth = exprFloorWidth ? expr.floorwidth.eval(paintParams.zoom) : props.floorwidth; + const auto floorwidth = exprFloorWidth ? expr.floorwidth.eval(paintParams.map_zoom) : props.floorwidth; #else - const auto floorwidth = unpack_mix_float(vertx.floorwidth, interp.floorwidth_t); + const auto floorwidth = unpack_mix_float(vertx.floorwidth, drawable.floorwidth_t); #endif // the distance over which the line edge fades out. @@ -804,13 +898,13 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], .tex_b = float2(linesofar * drawable.patternscale_b.x / floorwidth, v_normal.y * drawable.patternscale_b.y + drawable.tex_y_b), #if !defined(HAS_UNIFORM_u_color) - .color = unpack_mix_color(vertx.color, interp.color_t), + .color = unpack_mix_color(vertx.color, drawable.color_t), #endif #if !defined(HAS_UNIFORM_u_blur) - .blur = unpack_mix_float(vertx.blur, interp.blur_t), + .blur = unpack_mix_float(vertx.blur, drawable.blur_t), #endif #if !defined(HAS_UNIFORM_u_opacity) - .opacity = unpack_mix_float(vertx.opacity, interp.opacity_t), + .opacity = unpack_mix_float(vertx.opacity, drawable.opacity_t), #endif #if !defined(HAS_UNIFORM_u_floorwidth) .floorwidth = floorwidth, @@ -820,39 +914,43 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], half4 fragment fragmentMain(FragmentStage in [[stage_in]], device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], - device const LineSDFDrawableUBO& drawable [[buffer(idLineDrawableUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const LineTilePropsUnionUBO* tilePropsVector [[buffer(idLineTilePropsUBO)]], device const LineEvaluatedPropsUBO& props [[buffer(idLineEvaluatedPropsUBO)]], device const LineExpressionUBO& expr [[buffer(idLineExpressionUBO)]], texture2d image0 [[texture(0)]], sampler image0_sampler [[sampler(0)]]) { + #if defined(OVERDRAW_INSPECTOR) return half4(1.0); #endif + device const LineSDFTilePropsUBO& tileProps = tilePropsVector[uboIndex].lineSDFTilePropsUBO; + #if defined(HAS_UNIFORM_u_color) const auto exprColor = (props.expressionMask & LineExpressionMask::Color); - const auto color = exprColor ? expr.color.evalColor(paintParams.zoom) : props.color; + const auto color = exprColor ? expr.color.evalColor(paintParams.map_zoom) : props.color; #else const float4 color = in.color; #endif #if defined(HAS_UNIFORM_u_blur) const auto exprBlur = (props.expressionMask & LineExpressionMask::Blur); - const float blur = exprBlur ? expr.blur.eval(paintParams.zoom) : props.blur; + const float blur = exprBlur ? expr.blur.eval(paintParams.map_zoom) : props.blur; #else const float blur = in.blur; #endif #if defined(HAS_UNIFORM_u_opacity) const auto exprOpacity = (props.expressionMask & LineExpressionMask::Opacity); - const float opacity = exprOpacity ? expr.opacity.eval(paintParams.zoom) : props.opacity; + const float opacity = exprOpacity ? expr.opacity.eval(paintParams.map_zoom) : props.opacity; #else const float opacity = in.opacity; #endif #if defined(HAS_UNIFORM_u_floorwidth) const auto exprFloorWidth = (props.expressionMask & LineExpressionMask::FloorWidth); - const auto floorwidth = exprFloorWidth ? expr.floorwidth.eval(paintParams.zoom) : props.floorwidth; + const auto floorwidth = exprFloorWidth ? expr.floorwidth.eval(paintParams.map_zoom) : props.floorwidth; #else const auto floorwidth = in.floorwidth; #endif @@ -866,9 +964,9 @@ half4 fragment fragmentMain(FragmentStage in [[stage_in]], const float sdfdist_a = image0.sample(image0_sampler, in.tex_a).a; const float sdfdist_b = image0.sample(image0_sampler, in.tex_b).a; - const float sdfdist = mix(sdfdist_a, sdfdist_b, drawable.mix); + const float sdfdist = mix(sdfdist_a, sdfdist_b, tileProps.mix); const float alpha = clamp(min(dist - (in.width2.y - blur2), in.width2.x - dist) / blur2, 0.0, 1.0) * - smoothstep(0.5 - drawable.sdfgamma / floorwidth, 0.5 + drawable.sdfgamma / floorwidth, sdfdist); + smoothstep(0.5 - tileProps.sdfgamma / floorwidth, 0.5 + tileProps.sdfgamma / floorwidth, sdfdist); return half4(color * (alpha * opacity)); } diff --git a/include/mbgl/shaders/mtl/raster.hpp b/include/mbgl/shaders/mtl/raster.hpp index a6a489f4690..f8d13174ed7 100644 --- a/include/mbgl/shaders/mtl/raster.hpp +++ b/include/mbgl/shaders/mtl/raster.hpp @@ -2,12 +2,45 @@ #include #include -#include #include namespace mbgl { namespace shaders { +#define RASTER_SHADER_PRELUDE R"( + +struct alignas(16) RasterDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ +}; +static_assert(sizeof(RasterDrawableUBO) == 4 * 16, "wrong size"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) RasterEvaluatedPropsUBO { + /* 0 */ float4 spin_weights; + /* 16 */ float2 tl_parent; + /* 24 */ float scale_parent; + /* 28 */ float buffer_scale; + /* 32 */ float fade_t; + /* 36 */ float opacity; + /* 40 */ float brightness_low; + /* 44 */ float brightness_high; + /* 48 */ float saturation_factor; + /* 52 */ float contrast_factor; + /* 56 */ float pad1; + /* 60 */ float pad2; + /* 64 */ +}; +static_assert(sizeof(RasterEvaluatedPropsUBO) == 4 * 16, "wrong size"); + +enum { + idRasterDrawableUBO = globalUBOCount, + idRasterEvaluatedPropsUBO, + rasterUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "RasterShader"; @@ -19,11 +52,11 @@ struct ShaderSource { static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto source = R"( + static constexpr auto source = RASTER_SHADER_PRELUDE R"( struct VertexStage { - short2 pos [[attribute(3)]]; - short2 texture_pos [[attribute(4)]]; + short2 pos [[attribute(rasterUBOCount + 0)]]; + short2 texture_pos [[attribute(rasterUBOCount + 1)]]; }; struct FragmentStage { @@ -32,27 +65,12 @@ struct FragmentStage { float2 pos1; }; -struct alignas(16) RasterDrawableUBO { - float4x4 matrix; -}; - -struct alignas(16) RasterEvaluatedPropsUBO { - float4 spin_weights; - float2 tl_parent; - float scale_parent; - float buffer_scale; - float fade_t; - float opacity; - float brightness_low; - float brightness_high; - float saturation_factor; - float contrast_factor; - float pad1, pad2; -}; - FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const RasterDrawableUBO& drawable [[buffer(1)]], - device const RasterEvaluatedPropsUBO& props [[buffer(2)]]) { + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const RasterDrawableUBO* drawableVector [[buffer(idRasterDrawableUBO)]], + device const RasterEvaluatedPropsUBO& props [[buffer(idRasterEvaluatedPropsUBO)]]) { + + device const RasterDrawableUBO& drawable = drawableVector[uboIndex]; const float4 position = drawable.matrix * float4(float2(vertx.pos), 0, 1); @@ -72,7 +90,7 @@ FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], } half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const RasterEvaluatedPropsUBO& props [[buffer(2)]], + device const RasterEvaluatedPropsUBO& props [[buffer(idRasterEvaluatedPropsUBO)]], texture2d image0 [[texture(0)]], texture2d image1 [[texture(1)]], sampler image0_sampler [[sampler(0)]], diff --git a/include/mbgl/shaders/mtl/shader_group.hpp b/include/mbgl/shaders/mtl/shader_group.hpp index d4f5b5dbe82..e6d96fa7f55 100644 --- a/include/mbgl/shaders/mtl/shader_group.hpp +++ b/include/mbgl/shaders/mtl/shader_group.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/mbgl/shaders/mtl/symbol.hpp b/include/mbgl/shaders/mtl/symbol.hpp new file mode 100644 index 00000000000..e9db304715f --- /dev/null +++ b/include/mbgl/shaders/mtl/symbol.hpp @@ -0,0 +1,646 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace shaders { + +#define SYMBOL_SHADER_COMMON R"( + +struct alignas(16) SymbolDrawableUBO { + /* 0 */ float4x4 matrix; + /* 64 */ float4x4 label_plane_matrix; + /* 128 */ float4x4 coord_matrix; + + /* 192 */ float2 texsize; + /* 200 */ float2 texsize_icon; + + /* 208 */ /*bool*/ int is_text_prop; + /* 212 */ /*bool*/ int rotate_symbol; + /* 216 */ /*bool*/ int pitch_with_map; + /* 220 */ /*bool*/ int is_size_zoom_constant; + /* 224 */ /*bool*/ int is_size_feature_constant; + + /* 228 */ float size_t; + /* 232 */ float size; + + // Interpolations + /* 236 */ float fill_color_t; + /* 240 */ float halo_color_t; + /* 244 */ float opacity_t; + /* 248 */ float halo_width_t; + /* 252 */ float halo_blur_t; + /* 256 */ +}; +static_assert(sizeof(SymbolDrawableUBO) == 16 * 16, "wrong size"); + +struct alignas(16) SymbolTilePropsUBO { + /* 0 */ /*bool*/ int is_text; + /* 4 */ /*bool*/ int is_halo; + /* 8 */ float gamma_scale; + /* 12 */ float pad1; + /* 16 */ +}; +static_assert(sizeof(SymbolTilePropsUBO) == 16, "wrong size"); + +/// Evaluated properties that do not depend on the tile +struct alignas(16) SymbolEvaluatedPropsUBO { + /* 0 */ float4 text_fill_color; + /* 16 */ float4 text_halo_color; + /* 32 */ float text_opacity; + /* 36 */ float text_halo_width; + /* 40 */ float text_halo_blur; + /* 44 */ float pad1; + /* 48 */ float4 icon_fill_color; + /* 64 */ float4 icon_halo_color; + /* 80 */ float icon_opacity; + /* 84 */ float icon_halo_width; + /* 88 */ float icon_halo_blur; + /* 92 */ float pad2; + /* 96 */ +}; +static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "wrong size"); + +enum { + idSymbolDrawableUBO = globalUBOCount, + idSymbolTilePropsUBO, + idSymbolEvaluatedPropsUBO, + symbolUBOCount +}; + +)" + +template <> +struct ShaderSource { + static constexpr auto name = "SymbolIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = SYMBOL_SHADER_COMMON R"( +struct VertexStage { + float4 pos_offset [[attribute(symbolUBOCount + 0)]]; + float4 data [[attribute(symbolUBOCount + 1)]]; + float4 pixeloffset [[attribute(symbolUBOCount + 2)]]; + float3 projected_pos [[attribute(symbolUBOCount + 3)]]; + float fade_opacity [[attribute(symbolUBOCount + 4)]]; + +#if !defined(HAS_UNIFORM_u_opacity) + float opacity [[attribute(symbolUBOCount + 5)]]; +#endif +}; + +struct FragmentStage { + float4 position [[position, invariant]]; + half2 tex; + +#if defined(HAS_UNIFORM_u_opacity) + // We only need to pass `fade_opacity` separately if opacity is a + // uniform, otherwise it's multiplied into fragment opacity, below. + half fade_opacity; +#else + half opacity; +#endif +}; + +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const SymbolDrawableUBO* drawableVector [[buffer(idSymbolDrawableUBO)]]) { + + device const SymbolDrawableUBO& drawable = drawableVector[uboIndex]; + + const float2 a_pos = vertx.pos_offset.xy; + const float2 a_offset = vertx.pos_offset.zw; + + const float2 a_tex = vertx.data.xy; + const float2 a_size = vertx.data.zw; + + const float a_size_min = floor(a_size[0] * 0.5); + const float2 a_pxoffset = vertx.pixeloffset.xy; + const float2 a_minFontScale = vertx.pixeloffset.zw / 256.0; + + const float segment_angle = -vertx.projected_pos[2]; + + float size; + if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0; + } else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = a_size_min / 128.0; + } else { + size = drawable.size; + } + + const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); + const float camera_to_anchor_distance = projectedPoint.w; + // See comments in symbol_sdf.vertex + const float distance_ratio = drawable.pitch_with_map ? + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.camera_to_center_distance / camera_to_anchor_distance; + const float perspective_ratio = clamp( + 0.5 + 0.5 * distance_ratio, + 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles + 4.0); + + size *= perspective_ratio; + + const float fontScale = drawable.is_text_prop ? size / 24.0 : size; + + float symbol_rotation = 0.0; + if (drawable.rotate_symbol) { + // See comments in symbol_sdf.vertex + const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1); + + const float2 a = projectedPoint.xy / projectedPoint.w; + const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; + symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); + } + + const float angle_sin = sin(segment_angle + symbol_rotation); + const float angle_cos = cos(segment_angle + symbol_rotation); + const float2x2 rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos); + + const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0); + const float2 pos0 = projected_pos.xy / projected_pos.w; + const float2 posOffset = a_offset * max(a_minFontScale, fontScale) / 32.0 + a_pxoffset / 16.0; + const float4 position = drawable.coord_matrix * float4(pos0 + rotation_matrix * posOffset, 0.0, 1.0); + + const float2 raw_fade_opacity = unpack_opacity(vertx.fade_opacity); + const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; + const float fade_opacity = max(0.0, min(1.0, raw_fade_opacity[0] + fade_change)); + + return { + .position = position, + .tex = half2(a_tex / drawable.texsize), +#if defined(HAS_UNIFORM_u_opacity) + .fade_opacity = half(fade_opacity), +#else + .opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t) * fade_opacity), +#endif + }; +} + +half4 fragment fragmentMain(FragmentStage in [[stage_in]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const SymbolTilePropsUBO* tilePropsVector [[buffer(idSymbolTilePropsUBO)]], + device const SymbolEvaluatedPropsUBO& props [[buffer(idSymbolEvaluatedPropsUBO)]], + texture2d image [[texture(0)]], + sampler image_sampler [[sampler(0)]]) { +#if defined(OVERDRAW_INSPECTOR) + return half4(1.0); +#endif + + device const SymbolTilePropsUBO& tileProps = tilePropsVector[uboIndex]; + +#if defined(HAS_UNIFORM_u_opacity) + const float opacity = (tileProps.is_text ? props.text_opacity : props.icon_opacity) * in.fade_opacity; +#else + const float opacity = in.opacity; // fade_opacity is baked in for this case +#endif + + return half4(image.sample(image_sampler, float2(in.tex)) * opacity); +} +)"; +}; + +template <> +struct ShaderSource { + static constexpr auto name = "SymbolSDFIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = SYMBOL_SHADER_COMMON R"( +struct VertexStage { + float4 pos_offset [[attribute(symbolUBOCount + 0)]]; + float4 data [[attribute(symbolUBOCount + 1)]]; + float4 pixeloffset [[attribute(symbolUBOCount + 2)]]; + float3 projected_pos [[attribute(symbolUBOCount + 3)]]; + float fade_opacity [[attribute(symbolUBOCount + 4)]]; + +#if !defined(HAS_UNIFORM_u_fill_color) + float4 fill_color [[attribute(symbolUBOCount + 5)]]; +#endif +#if !defined(HAS_UNIFORM_u_halo_color) + float4 halo_color [[attribute(symbolUBOCount + 6)]]; +#endif +#if !defined(HAS_UNIFORM_u_opacity) + float opacity [[attribute(symbolUBOCount + 7)]]; +#endif +#if !defined(HAS_UNIFORM_u_halo_width) + float halo_width [[attribute(symbolUBOCount + 8)]]; +#endif +#if !defined(HAS_UNIFORM_u_halo_blur) + float halo_blur [[attribute(symbolUBOCount + 9)]]; +#endif +}; + +struct FragmentStage { + float4 position [[position, invariant]]; + +#if !defined(HAS_UNIFORM_u_fill_color) + half4 fill_color; +#endif +#if !defined(HAS_UNIFORM_u_halo_color) + half4 halo_color; +#endif + + half2 tex; + half gamma_scale; + half fontScale; + half fade_opacity; + +#if !defined(HAS_UNIFORM_u_opacity) + half opacity; +#endif +#if !defined(HAS_UNIFORM_u_halo_width) + half halo_width; +#endif +#if !defined(HAS_UNIFORM_u_halo_blur) + half halo_blur; +#endif +}; + +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const SymbolDrawableUBO* drawableVector [[buffer(idSymbolDrawableUBO)]]) { + + device const SymbolDrawableUBO& drawable = drawableVector[uboIndex]; + + const float2 a_pos = vertx.pos_offset.xy; + const float2 a_offset = vertx.pos_offset.zw; + + const float2 a_tex = vertx.data.xy; + const float2 a_size = vertx.data.zw; + + const float a_size_min = floor(a_size[0] * 0.5); + const float2 a_pxoffset = vertx.pixeloffset.xy; + + const float segment_angle = -vertx.projected_pos[2]; + + float size; + if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0; + } else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = a_size_min / 128.0; + } else { + size = drawable.size; + } + + const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); + const float camera_to_anchor_distance = projectedPoint.w; + // If the label is pitched with the map, layout is done in pitched space, + // which makes labels in the distance smaller relative to viewport space. + // We counteract part of that effect by multiplying by the perspective ratio. + // If the label isn't pitched with the map, we do layout in viewport space, + // which makes labels in the distance larger relative to the features around + // them. We counteract part of that effect by dividing by the perspective ratio. + const float distance_ratio = drawable.pitch_with_map ? + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.camera_to_center_distance / camera_to_anchor_distance; + const float perspective_ratio = clamp( + 0.5 + 0.5 * distance_ratio, + 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles + 4.0); + + size *= perspective_ratio; + + const float fontScale = drawable.is_text_prop ? size / 24.0 : size; + + float symbol_rotation = 0.0; + if (drawable.rotate_symbol) { + // Point labels with 'rotation-alignment: map' are horizontal with respect to tile units + // To figure out that angle in projected space, we draw a short horizontal line in tile + // space, project it, and measure its angle in projected space. + const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1); + + const float2 a = projectedPoint.xy / projectedPoint.w; + const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; + + symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); + } + + const float angle_sin = sin(segment_angle + symbol_rotation); + const float angle_cos = cos(segment_angle + symbol_rotation); + const auto rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos); + const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0); + const float2 pos_rot = a_offset / 32.0 * fontScale + a_pxoffset; + const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot; + const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0); + const float2 fade_opacity = unpack_opacity(vertx.fade_opacity); + const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; + + return { + .position = position, +#if !defined(HAS_UNIFORM_u_fill_color) + .fill_color = half4(unpack_mix_color(vertx.fill_color, drawable.fill_color_t)), +#endif +#if !defined(HAS_UNIFORM_u_halo_color) + .halo_color = half4(unpack_mix_color(vertx.halo_color, drawable.halo_color_t)), +#endif +#if !defined(HAS_UNIFORM_u_halo_width) + .halo_width = half(unpack_mix_float(vertx.halo_width, drawable.halo_width_t)), +#endif +#if !defined(HAS_UNIFORM_u_halo_blur) + .halo_blur = half(unpack_mix_float(vertx.halo_blur, drawable.halo_blur_t)), +#endif +#if !defined(HAS_UNIFORM_u_opacity) + .opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)), +#endif + .tex = half2(a_tex / drawable.texsize), + .gamma_scale = half(position.w), + .fontScale = half(fontScale), + .fade_opacity = half(max(0.0, min(1.0, fade_opacity[0] + fade_change))), + }; +} + +half4 fragment fragmentMain(FragmentStage in [[stage_in]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const SymbolTilePropsUBO* tilePropsVector [[buffer(idSymbolTilePropsUBO)]], + device const SymbolEvaluatedPropsUBO& props [[buffer(idSymbolEvaluatedPropsUBO)]], + texture2d image [[texture(0)]], + sampler image_sampler [[sampler(0)]]) { +#if defined(OVERDRAW_INSPECTOR) + return half4(1.0); +#endif + + device const SymbolTilePropsUBO& tileProps = tilePropsVector[uboIndex]; + +#if defined(HAS_UNIFORM_u_fill_color) + const half4 fill_color = half4(tileProps.is_text ? props.text_fill_color : props.icon_fill_color); +#else + const half4 fill_color = in.fill_color; +#endif +#if defined(HAS_UNIFORM_u_halo_color) + const half4 halo_color = half4(tileProps.is_text ? props.text_halo_color : props.icon_halo_color); +#else + const half4 halo_color = in.halo_color; +#endif +#if defined(HAS_UNIFORM_u_opacity) + const float opacity = tileProps.is_text ? props.text_opacity : props.icon_opacity; +#else + const float opacity = in.opacity; +#endif +#if defined(HAS_UNIFORM_u_halo_width) + const float halo_width = tileProps.is_text ? props.text_halo_width : props.icon_halo_width; +#else + const float halo_width = in.halo_width; +#endif +#if defined(HAS_UNIFORM_u_halo_blur) + const float halo_blur = tileProps.is_text ? props.text_halo_blur : props.icon_halo_blur; +#else + const float halo_blur = in.halo_blur; +#endif + + const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO; + const float fontGamma = in.fontScale * tileProps.gamma_scale; + const half4 color = tileProps.is_halo ? halo_color : fill_color; + const float gamma = ((tileProps.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; + const float buff = tileProps.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0; + const float dist = image.sample(image_sampler, float2(in.tex)).a; + const float gamma_scaled = gamma * in.gamma_scale; + const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); + + return half4(color * (alpha * opacity * in.fade_opacity)); +} +)"; +}; + +template <> +struct ShaderSource { + static constexpr auto name = "SymbolTextAndIconShader"; + static constexpr auto vertexMainFunction = "vertexMain"; + static constexpr auto fragmentMainFunction = "fragmentMain"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto source = SYMBOL_SHADER_COMMON R"( +#define SDF 1.0 +#define ICON 0.0 + +struct VertexStage { + float4 pos_offset [[attribute(symbolUBOCount + 0)]]; + float4 data [[attribute(symbolUBOCount + 1)]]; + float3 projected_pos [[attribute(symbolUBOCount + 2)]]; + float fade_opacity [[attribute(symbolUBOCount + 3)]]; + +#if !defined(HAS_UNIFORM_u_fill_color) + float4 fill_color [[attribute(symbolUBOCount + 4)]]; +#endif +#if !defined(HAS_UNIFORM_u_halo_color) + float4 halo_color [[attribute(symbolUBOCount + 5)]]; +#endif +#if !defined(HAS_UNIFORM_u_opacity) + float opacity [[attribute(symbolUBOCount + 6)]]; +#endif +#if !defined(HAS_UNIFORM_u_halo_width) + float halo_width [[attribute(symbolUBOCount + 7)]]; +#endif +#if !defined(HAS_UNIFORM_u_halo_blur) + float halo_blur [[attribute(symbolUBOCount + 8)]]; +#endif +}; + +struct FragmentStage { + float4 position [[position, invariant]]; + +#if !defined(HAS_UNIFORM_u_fill_color) + half4 fill_color; +#endif +#if !defined(HAS_UNIFORM_u_halo_color) + half4 halo_color; +#endif + + half2 tex; + +#if !defined(HAS_UNIFORM_u_opacity) + half opacity; +#endif +#if !defined(HAS_UNIFORM_u_halo_width) + half halo_width; +#endif +#if !defined(HAS_UNIFORM_u_halo_blur) + half halo_blur; +#endif + + half gamma_scale; + half fontScale; + half fade_opacity; + bool is_icon; +}; + +FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], + device const GlobalPaintParamsUBO& paintParams [[buffer(idGlobalPaintParamsUBO)]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const SymbolDrawableUBO* drawableVector [[buffer(idSymbolDrawableUBO)]]) { + + device const SymbolDrawableUBO& drawable = drawableVector[uboIndex]; + + const float2 a_pos = vertx.pos_offset.xy; + const float2 a_offset = vertx.pos_offset.zw; + + const float2 a_tex = vertx.data.xy; + const float2 a_size = vertx.data.zw; + + const float a_size_min = floor(a_size[0] * 0.5); + const float is_sdf = a_size[0] - 2.0 * a_size_min; + + const float segment_angle = -vertx.projected_pos[2]; + + float size; + if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0; + } else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = a_size_min / 128.0; + } else { + size = drawable.size; + } + + const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); + const float camera_to_anchor_distance = projectedPoint.w; + // If the label is pitched with the map, layout is done in pitched space, + // which makes labels in the distance smaller relative to viewport space. + // We counteract part of that effect by multiplying by the perspective ratio. + // If the label isn't pitched with the map, we do layout in viewport space, + // which makes labels in the distance larger relative to the features around + // them. We counteract part of that effect by dividing by the perspective ratio. + const float distance_ratio = drawable.pitch_with_map ? + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.camera_to_center_distance / camera_to_anchor_distance; + const float perspective_ratio = clamp( + 0.5 + 0.5 * distance_ratio, + 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles + 4.0); + + size *= perspective_ratio; + + const float fontScale = size / 24.0; + + float symbol_rotation = 0.0; + if (drawable.rotate_symbol) { + // Point labels with 'rotation-alignment: map' are horizontal with respect to tile units + // To figure out that angle in projected space, we draw a short horizontal line in tile + // space, project it, and measure its angle in projected space. + const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1); + + const float2 a = projectedPoint.xy / projectedPoint.w; + const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; + + symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); + } + + const float angle_sin = sin(segment_angle + symbol_rotation); + const float angle_cos = cos(segment_angle + symbol_rotation); + const float2x2 rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos); + + const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0); + const float2 pos_rot = a_offset / 32.0 * fontScale; + const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot; + const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0); + const float gamma_scale = position.w; + + const float2 fade_opacity = unpack_opacity(vertx.fade_opacity); + const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; + const bool is_icon = (is_sdf == ICON); + + return { + .position = position, + .tex = half2(a_tex / (is_icon ? drawable.texsize_icon : drawable.texsize)), + .gamma_scale = half(gamma_scale), + .fontScale = half(fontScale), + .fade_opacity = half(max(0.0, min(1.0, fade_opacity[0] + fade_change))), + .is_icon = is_icon, + +#if !defined(HAS_UNIFORM_u_fill_color) + .fill_color = half(unpack_mix_color(vertx.fill_color, drawable.fill_color_t)); +#endif +#if !defined(HAS_UNIFORM_u_halo_color) + .halo_color = half(unpack_mix_color(vertx.halo_color, drawable.halo_color_t)); +#endif +#if !defined(HAS_UNIFORM_u_opacity) + .opacity = half(unpack_mix_float(vertx.opacity, drawable.opacity_t)); +#endif +#if !defined(HAS_UNIFORM_u_halo_width) + .halo_width = half(unpack_mix_float(vertx.halo_width, drawable.halo_width_t)); +#endif +#if !defined(HAS_UNIFORM_u_halo_blur) + .halo_blur = half(unpack_mix_float(vertx.halo_blur, drawable.halo_blur_t)); +#endif + }; +} + +half4 fragment fragmentMain(FragmentStage in [[stage_in]], + device const uint32_t& uboIndex [[buffer(idGlobalUBOIndex)]], + device const SymbolTilePropsUBO* tilePropsVector [[buffer(idSymbolTilePropsUBO)]], + device const SymbolEvaluatedPropsUBO& props [[buffer(idSymbolEvaluatedPropsUBO)]], + texture2d glyph_image [[texture(0)]], + texture2d icon_image [[texture(1)]], + sampler glyph_sampler [[sampler(0)]], + sampler icon_sampler [[sampler(1)]]) { +#if defined(OVERDRAW_INSPECTOR) + return half4(1.0); +#endif + + device const SymbolTilePropsUBO& tileProps = tilePropsVector[uboIndex]; + +#if defined(HAS_UNIFORM_u_fill_color) + const half4 fill_color = half4(tileProps.is_text ? props.text_fill_color : props.icon_fill_color); +#else + const half4 fill_color = in.fill_color; +#endif +#if defined(HAS_UNIFORM_u_halo_color) + const half4 halo_color = half4(tileProps.is_text ? props.text_halo_color : props.icon_halo_color); +#else + const half4 halo_color = in.halo_color; +#endif +#if defined(HAS_UNIFORM_u_opacity) + const half opacity = half(tileProps.is_text ? props.text_opacity : props.icon_opacity); +#else + const half opacity = in.opacity; +#endif +#if defined(HAS_UNIFORM_u_halo_width) + const half halo_width = half(tileProps.is_text ? props.text_halo_width : props.icon_halo_width); +#else + const half halo_width = in.halo_width; +#endif +#if defined(HAS_UNIFORM_u_halo_blur) + const half halo_blur = half(tileProps.is_text ? props.text_halo_blur : props.icon_halo_blur); +#else + const half halo_blur = in.halo_blur; +#endif + + if (in.is_icon) { + const float alpha = opacity * in.fade_opacity; + return half4(icon_image.sample(icon_sampler, float2(in.tex)) * alpha); + } + + const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO; + const half4 color = tileProps.is_halo ? halo_color : fill_color; + const float fontGamma = in.fontScale * tileProps.gamma_scale; + const float gamma = ((tileProps.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; + const float buff = tileProps.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0; + const float dist = glyph_image.sample(glyph_sampler, float2(in.tex)).a; + const float gamma_scaled = gamma * in.gamma_scale; + const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); + + return half4(color * (alpha * opacity * in.fade_opacity)); +} +)"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/symbol_icon.hpp b/include/mbgl/shaders/mtl/symbol_icon.hpp deleted file mode 100644 index 31ebaf5ff93..00000000000 --- a/include/mbgl/shaders/mtl/symbol_icon.hpp +++ /dev/null @@ -1,145 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr auto name = "SymbolIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = R"( -struct VertexStage { - float4 pos_offset [[attribute(5)]]; - float4 data [[attribute(6)]]; - float4 pixeloffset [[attribute(7)]]; - float3 projected_pos [[attribute(8)]]; - float fade_opacity [[attribute(9)]]; - -#if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(10)]]; -#endif -}; - -struct FragmentStage { - float4 position [[position, invariant]]; - half2 tex; - -#if defined(HAS_UNIFORM_u_opacity) - // We only need to pass `fade_opacity` separately if opacity is a - // uniform, otherwise it's multiplied into fragment opacity, below. - half fade_opacity; -#else - half opacity; -#endif -}; - -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const SymbolDrawableUBO& drawable [[buffer(1)]], - device const SymbolTilePropsUBO& tileprops [[buffer(2)]], - device const SymbolInterpolateUBO& interp [[buffer(3)]]) { - - const float2 a_pos = vertx.pos_offset.xy; - const float2 a_offset = vertx.pos_offset.zw; - - const float2 a_tex = vertx.data.xy; - const float2 a_size = vertx.data.zw; - - const float a_size_min = floor(a_size[0] * 0.5); - const float2 a_pxoffset = vertx.pixeloffset.xy; - const float2 a_minFontScale = vertx.pixeloffset.zw / 256.0; - - const float segment_angle = -vertx.projected_pos[2]; - - float size; - if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0; - } else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { - size = a_size_min / 128.0; - } else { - size = tileprops.size; - } - - const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); - const float camera_to_anchor_distance = projectedPoint.w; - // See comments in symbol_sdf.vertex - const float distance_ratio = tileprops.pitch_with_map ? - camera_to_anchor_distance / paintParams.camera_to_center_distance : - paintParams.camera_to_center_distance / camera_to_anchor_distance; - const float perspective_ratio = clamp( - 0.5 + 0.5 * distance_ratio, - 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles - 4.0); - - size *= perspective_ratio; - - const float fontScale = tileprops.is_text ? size / 24.0 : size; - - float symbol_rotation = 0.0; - if (drawable.rotate_symbol) { - // See comments in symbol_sdf.vertex - const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1); - - const float2 a = projectedPoint.xy / projectedPoint.w; - const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; - symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); - } - - const float angle_sin = sin(segment_angle + symbol_rotation); - const float angle_cos = cos(segment_angle + symbol_rotation); - const float2x2 rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos); - - const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0); - const float2 pos0 = projected_pos.xy / projected_pos.w; - const float2 posOffset = a_offset * max(a_minFontScale, fontScale) / 32.0 + a_pxoffset / 16.0; - const float4 position = drawable.coord_matrix * float4(pos0 + rotation_matrix * posOffset, 0.0, 1.0); - - const float2 raw_fade_opacity = unpack_opacity(vertx.fade_opacity); - const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; - const float fade_opacity = max(0.0, min(1.0, raw_fade_opacity[0] + fade_change)); - - return { - .position = position, - .tex = half2(a_tex / drawable.texsize), -#if defined(HAS_UNIFORM_u_opacity) - .fade_opacity = half(fade_opacity), -#else - .opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t) * fade_opacity), -#endif - }; -} - -half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolTilePropsUBO& tileprops [[buffer(2)]], - device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], - texture2d image [[texture(0)]], - sampler image_sampler [[sampler(0)]]) { -#if defined(OVERDRAW_INSPECTOR) - return half4(1.0); -#endif - -#if defined(HAS_UNIFORM_u_opacity) - const float opacity = (tileprops.is_text ? props.text_opacity : props.icon_opacity) * in.fade_opacity; -#else - const float opacity = in.opacity; // fade_opacity is baked in for this case -#endif - - return half4(image.sample(image_sampler, float2(in.tex)) * opacity); -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/symbol_sdf.hpp b/include/mbgl/shaders/mtl/symbol_sdf.hpp deleted file mode 100644 index c4c784d059e..00000000000 --- a/include/mbgl/shaders/mtl/symbol_sdf.hpp +++ /dev/null @@ -1,217 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr auto name = "SymbolSDFIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = R"( -struct VertexStage { - float4 pos_offset [[attribute(5)]]; - float4 data [[attribute(6)]]; - float4 pixeloffset [[attribute(7)]]; - float3 projected_pos [[attribute(8)]]; - float fade_opacity [[attribute(9)]]; - -#if !defined(HAS_UNIFORM_u_fill_color) - float4 fill_color [[attribute(10)]]; -#endif -#if !defined(HAS_UNIFORM_u_halo_color) - float4 halo_color [[attribute(11)]]; -#endif -#if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(12)]]; -#endif -#if !defined(HAS_UNIFORM_u_halo_width) - float halo_width [[attribute(13)]]; -#endif -#if !defined(HAS_UNIFORM_u_halo_blur) - float halo_blur [[attribute(14)]]; -#endif -}; - -struct FragmentStage { - float4 position [[position, invariant]]; - -#if !defined(HAS_UNIFORM_u_fill_color) - half4 fill_color; -#endif -#if !defined(HAS_UNIFORM_u_halo_color) - half4 halo_color; -#endif - - half2 tex; - half gamma_scale; - half fontScale; - half fade_opacity; - -#if !defined(HAS_UNIFORM_u_opacity) - half opacity; -#endif -#if !defined(HAS_UNIFORM_u_halo_width) - half halo_width; -#endif -#if !defined(HAS_UNIFORM_u_halo_blur) - half halo_blur; -#endif -}; - -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const SymbolDrawableUBO& drawable [[buffer(1)]], - device const SymbolTilePropsUBO& tileprops [[buffer(2)]], - device const SymbolInterpolateUBO& interp [[buffer(3)]]) { - - const float2 a_pos = vertx.pos_offset.xy; - const float2 a_offset = vertx.pos_offset.zw; - - const float2 a_tex = vertx.data.xy; - const float2 a_size = vertx.data.zw; - - const float a_size_min = floor(a_size[0] * 0.5); - const float2 a_pxoffset = vertx.pixeloffset.xy; - - const float segment_angle = -vertx.projected_pos[2]; - - float size; - if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0; - } else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { - size = a_size_min / 128.0; - } else { - size = tileprops.size; - } - - const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); - const float camera_to_anchor_distance = projectedPoint.w; - // If the label is pitched with the map, layout is done in pitched space, - // which makes labels in the distance smaller relative to viewport space. - // We counteract part of that effect by multiplying by the perspective ratio. - // If the label isn't pitched with the map, we do layout in viewport space, - // which makes labels in the distance larger relative to the features around - // them. We counteract part of that effect by dividing by the perspective ratio. - const float distance_ratio = tileprops.pitch_with_map ? - camera_to_anchor_distance / paintParams.camera_to_center_distance : - paintParams.camera_to_center_distance / camera_to_anchor_distance; - const float perspective_ratio = clamp( - 0.5 + 0.5 * distance_ratio, - 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles - 4.0); - - size *= perspective_ratio; - - const float fontScale = tileprops.is_text ? size / 24.0 : size; - - float symbol_rotation = 0.0; - if (drawable.rotate_symbol) { - // Point labels with 'rotation-alignment: map' are horizontal with respect to tile units - // To figure out that angle in projected space, we draw a short horizontal line in tile - // space, project it, and measure its angle in projected space. - const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1); - - const float2 a = projectedPoint.xy / projectedPoint.w; - const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; - - symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); - } - - const float angle_sin = sin(segment_angle + symbol_rotation); - const float angle_cos = cos(segment_angle + symbol_rotation); - const auto rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos); - const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0); - const float2 pos_rot = a_offset / 32.0 * fontScale + a_pxoffset; - const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot; - const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0); - const float2 fade_opacity = unpack_opacity(vertx.fade_opacity); - const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; - - return { - .position = position, -#if !defined(HAS_UNIFORM_u_fill_color) - .fill_color = half4(unpack_mix_color(vertx.fill_color, interp.fill_color_t)), -#endif -#if !defined(HAS_UNIFORM_u_halo_color) - .halo_color = half4(unpack_mix_color(vertx.halo_color, interp.halo_color_t)), -#endif -#if !defined(HAS_UNIFORM_u_halo_width) - .halo_width = half(unpack_mix_float(vertx.halo_width, interp.halo_width_t)), -#endif -#if !defined(HAS_UNIFORM_u_halo_blur) - .halo_blur = half(unpack_mix_float(vertx.halo_blur, interp.halo_blur_t)), -#endif -#if !defined(HAS_UNIFORM_u_opacity) - .opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)), -#endif - .tex = half2(a_tex / drawable.texsize), - .gamma_scale = half(position.w), - .fontScale = half(fontScale), - .fade_opacity = half(max(0.0, min(1.0, fade_opacity[0] + fade_change))), - }; -} - -half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(1)]], - device const SymbolTilePropsUBO& tileprops [[buffer(2)]], - device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], - texture2d image [[texture(0)]], - sampler image_sampler [[sampler(0)]]) { -#if defined(OVERDRAW_INSPECTOR) - return half4(1.0); -#endif - -#if defined(HAS_UNIFORM_u_fill_color) - const half4 fill_color = half4(tileprops.is_text ? props.text_fill_color : props.icon_fill_color); -#else - const half4 fill_color = in.fill_color; -#endif -#if defined(HAS_UNIFORM_u_halo_color) - const half4 halo_color = half4(tileprops.is_text ? props.text_halo_color : props.icon_halo_color); -#else - const half4 halo_color = in.halo_color; -#endif -#if defined(HAS_UNIFORM_u_opacity) - const float opacity = tileprops.is_text ? props.text_opacity : props.icon_opacity; -#else - const float opacity = in.opacity; -#endif -#if defined(HAS_UNIFORM_u_halo_width) - const float halo_width = tileprops.is_text ? props.text_halo_width : props.icon_halo_width; -#else - const float halo_width = in.halo_width; -#endif -#if defined(HAS_UNIFORM_u_halo_blur) - const float halo_blur = tileprops.is_text ? props.text_halo_blur : props.icon_halo_blur; -#else - const float halo_blur = in.halo_blur; -#endif - - const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO; - const float fontGamma = in.fontScale * drawable.gamma_scale; - const half4 color = tileprops.is_halo ? halo_color : fill_color; - const float gamma = ((tileprops.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; - const float buff = tileprops.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0; - const float dist = image.sample(image_sampler, float2(in.tex)).a; - const float gamma_scaled = gamma * in.gamma_scale; - const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); - - return half4(color * (alpha * opacity * in.fade_opacity)); -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp b/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp deleted file mode 100644 index 195150c16c3..00000000000 --- a/include/mbgl/shaders/mtl/symbol_text_and_icon.hpp +++ /dev/null @@ -1,234 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace mbgl { -namespace shaders { - -template <> -struct ShaderSource { - static constexpr auto name = "SymbolTextAndIconShader"; - static constexpr auto vertexMainFunction = "vertexMain"; - static constexpr auto fragmentMainFunction = "fragmentMain"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto source = R"( -#define SDF 1.0 -#define ICON 0.0 - -struct VertexStage { - float4 pos_offset [[attribute(5)]]; - float4 data [[attribute(6)]]; - float3 projected_pos [[attribute(7)]]; - float fade_opacity [[attribute(8)]]; - -#if !defined(HAS_UNIFORM_u_fill_color) - float4 fill_color [[attribute(9)]]; -#endif -#if !defined(HAS_UNIFORM_u_halo_color) - float4 halo_color [[attribute(10)]]; -#endif -#if !defined(HAS_UNIFORM_u_opacity) - float opacity [[attribute(11)]]; -#endif -#if !defined(HAS_UNIFORM_u_halo_width) - float halo_width [[attribute(12)]]; -#endif -#if !defined(HAS_UNIFORM_u_halo_blur) - float halo_blur [[attribute(13)]]; -#endif -}; - -struct FragmentStage { - float4 position [[position, invariant]]; - -#if !defined(HAS_UNIFORM_u_fill_color) - half4 fill_color; -#endif -#if !defined(HAS_UNIFORM_u_halo_color) - half4 halo_color; -#endif - - half2 tex; - -#if !defined(HAS_UNIFORM_u_opacity) - half opacity; -#endif -#if !defined(HAS_UNIFORM_u_halo_width) - half halo_width; -#endif -#if !defined(HAS_UNIFORM_u_halo_blur) - half halo_blur; -#endif - - half gamma_scale; - half fontScale; - half fade_opacity; - bool is_icon; -}; - -FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]], - device const GlobalPaintParamsUBO& paintParams [[buffer(0)]], - device const SymbolDrawableUBO& drawable [[buffer(1)]], - device const SymbolTilePropsUBO& tileprops [[buffer(2)]], - device const SymbolInterpolateUBO& interp [[buffer(3)]]) { - - const float2 a_pos = vertx.pos_offset.xy; - const float2 a_offset = vertx.pos_offset.zw; - - const float2 a_tex = vertx.data.xy; - const float2 a_size = vertx.data.zw; - - const float a_size_min = floor(a_size[0] * 0.5); - const float is_sdf = a_size[0] - 2.0 * a_size_min; - - const float segment_angle = -vertx.projected_pos[2]; - - float size; - if (!tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], tileprops.size_t) / 128.0; - } else if (tileprops.is_size_zoom_constant && !tileprops.is_size_feature_constant) { - size = a_size_min / 128.0; - } else { - size = tileprops.size; - } - - const float4 projectedPoint = drawable.matrix * float4(a_pos, 0, 1); - const float camera_to_anchor_distance = projectedPoint.w; - // If the label is pitched with the map, layout is done in pitched space, - // which makes labels in the distance smaller relative to viewport space. - // We counteract part of that effect by multiplying by the perspective ratio. - // If the label isn't pitched with the map, we do layout in viewport space, - // which makes labels in the distance larger relative to the features around - // them. We counteract part of that effect by dividing by the perspective ratio. - const float distance_ratio = tileprops.pitch_with_map ? - camera_to_anchor_distance / paintParams.camera_to_center_distance : - paintParams.camera_to_center_distance / camera_to_anchor_distance; - const float perspective_ratio = clamp( - 0.5 + 0.5 * distance_ratio, - 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles - 4.0); - - size *= perspective_ratio; - - const float fontScale = size / 24.0; - - float symbol_rotation = 0.0; - if (drawable.rotate_symbol) { - // Point labels with 'rotation-alignment: map' are horizontal with respect to tile units - // To figure out that angle in projected space, we draw a short horizontal line in tile - // space, project it, and measure its angle in projected space. - const float4 offsetProjectedPoint = drawable.matrix * float4(a_pos + float2(1, 0), 0, 1); - - const float2 a = projectedPoint.xy / projectedPoint.w; - const float2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; - - symbol_rotation = atan2((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); - } - - const float angle_sin = sin(segment_angle + symbol_rotation); - const float angle_cos = cos(segment_angle + symbol_rotation); - const float2x2 rotation_matrix = float2x2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos); - - const float4 projected_pos = drawable.label_plane_matrix * float4(vertx.projected_pos.xy, 0.0, 1.0); - const float2 pos_rot = a_offset / 32.0 * fontScale; - const float2 pos0 = projected_pos.xy / projected_pos.w + rotation_matrix * pos_rot; - const float4 position = drawable.coord_matrix * float4(pos0, 0.0, 1.0); - const float gamma_scale = position.w; - - const float2 fade_opacity = unpack_opacity(vertx.fade_opacity); - const float fade_change = (fade_opacity[1] > 0.5) ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; - const bool is_icon = (is_sdf == ICON); - - return { - .position = position, - .tex = half2(a_tex / (is_icon ? drawable.texsize_icon : drawable.texsize)), - .gamma_scale = half(gamma_scale), - .fontScale = half(fontScale), - .fade_opacity = half(max(0.0, min(1.0, fade_opacity[0] + fade_change))), - .is_icon = is_icon, - -#if !defined(HAS_UNIFORM_u_fill_color) - .fill_color = half(unpack_mix_color(vertx.fill_color, interp.fill_color_t)); -#endif -#if !defined(HAS_UNIFORM_u_halo_color) - .halo_color = half(unpack_mix_color(vertx.halo_color, interp.halo_color_t)); -#endif -#if !defined(HAS_UNIFORM_u_opacity) - .opacity = half(unpack_mix_float(vertx.opacity, interp.opacity_t)); -#endif -#if !defined(HAS_UNIFORM_u_halo_width) - .halo_width = half(unpack_mix_float(vertx.halo_width, interp.halo_width_t)); -#endif -#if !defined(HAS_UNIFORM_u_halo_blur) - .halo_blur = half(unpack_mix_float(vertx.halo_blur, interp.halo_blur_t)); -#endif - }; -} - -half4 fragment fragmentMain(FragmentStage in [[stage_in]], - device const SymbolDrawableUBO& drawable [[buffer(1)]], - device const SymbolTilePropsUBO& tileprops [[buffer(2)]], - device const SymbolEvaluatedPropsUBO& props [[buffer(4)]], - texture2d glyph_image [[texture(0)]], - texture2d icon_image [[texture(1)]], - sampler glyph_sampler [[sampler(0)]], - sampler icon_sampler [[sampler(1)]]) { -#if defined(OVERDRAW_INSPECTOR) - return half4(1.0); -#endif - -#if defined(HAS_UNIFORM_u_fill_color) - const half4 fill_color = half4(tileprops.is_text ? props.text_fill_color : props.icon_fill_color); -#else - const half4 fill_color = in.fill_color; -#endif -#if defined(HAS_UNIFORM_u_halo_color) - const half4 halo_color = half4(tileprops.is_text ? props.text_halo_color : props.icon_halo_color); -#else - const half4 halo_color = in.halo_color; -#endif -#if defined(HAS_UNIFORM_u_opacity) - const half opacity = half(tileprops.is_text ? props.text_opacity : props.icon_opacity); -#else - const half opacity = in.opacity; -#endif -#if defined(HAS_UNIFORM_u_halo_width) - const half halo_width = half(tileprops.is_text ? props.text_halo_width : props.icon_halo_width); -#else - const half halo_width = in.halo_width; -#endif -#if defined(HAS_UNIFORM_u_halo_blur) - const half halo_blur = half(tileprops.is_text ? props.text_halo_blur : props.icon_halo_blur); -#else - const half halo_blur = in.halo_blur; -#endif - - if (in.is_icon) { - const float alpha = opacity * in.fade_opacity; - return half4(icon_image.sample(icon_sampler, float2(in.tex)) * alpha); - } - - const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO; - const half4 color = tileprops.is_halo ? halo_color : fill_color; - const float fontGamma = in.fontScale * drawable.gamma_scale; - const float gamma = ((tileprops.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; - const float buff = tileprops.is_halo ? (6.0 - halo_width / in.fontScale) / SDF_PX : (256.0 - 64.0) / 256.0; - const float dist = glyph_image.sample(glyph_sampler, float2(in.tex)).a; - const float gamma_scaled = gamma * in.gamma_scale; - const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); - - return half4(color * (alpha * opacity * in.fade_opacity)); -} -)"; -}; - -} // namespace shaders -} // namespace mbgl diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index 59fa51f2afe..d984a2c7326 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -1,36 +1,34 @@ #pragma once +#include #include -#include #include -#include -#include namespace mbgl { namespace shaders { +#define WIDEVECTOR_SHADER_PRELUDE R"( + +enum { + idWideVectorUniformsUBO = globalUBOCount, + idWideVectorUniformWideVecUBO, + wideVectorUBOCount +}; + +)" + template <> struct ShaderSource { static constexpr auto name = "WideVectorShader"; static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; - static constexpr std::array uniforms{ - UniformBlockInfo{true, false, sizeof(WideVectorUniformsUBO), idWideVectorUniformsUBO}, - UniformBlockInfo{true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO}, - }; - static constexpr std::array attributes{ - AttributeInfo{wideVectorDrawableUBOCount + 0, gfx::AttributeDataType::Float3, idWideVectorScreenPos}, - AttributeInfo{wideVectorDrawableUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor}, - AttributeInfo{wideVectorDrawableUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}}; - static constexpr std::array instanceAttributes{ - AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter}, - AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Float4, idWideVectorInstanceColor}, - AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstancePrevious}, - AttributeInfo{wideVectorDrawableUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstanceNext}}; - static constexpr std::array textures{}; - - static constexpr auto source = R"( + static const std::array uniforms; + static const std::array attributes; + static const std::array instanceAttributes; + static const std::array textures; + + static constexpr auto source = WIDEVECTOR_SHADER_PRELUDE R"( #include namespace WhirlyKitShader @@ -113,9 +111,9 @@ typedef struct struct VertexTriWideVecB { // x, y offset around the center - float3 screenPos [[attribute(3)]]; - float4 color [[attribute(4)]]; - int index [[attribute(5)]]; + float3 screenPos [[attribute(wideVectorUBOCount + 0)]]; + float4 color [[attribute(wideVectorUBOCount + 1)]]; + int index [[attribute(wideVectorUBOCount + 2)]]; }; // Wide vector vertex passed to fragment shader (new version) @@ -222,10 +220,10 @@ constant constexpr float4 discardPt(0,0,-1e6,NAN); // Performance version of wide vector shader vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf( thread const VertexTriWideVecB vert [[ stage_in ]], - constant Uniforms &uniforms [[ buffer(1) ]], - constant UniformWideVec &wideVec [[ buffer(2) ]], + constant Uniforms &uniforms [[ buffer(idWideVectorUniformsUBO) ]], + constant UniformWideVec &wideVec [[ buffer(idWideVectorUniformWideVecUBO) ]], uint instanceID [[ instance_id ]], - constant VertexTriWideVecInstance *wideVecInsts [[ buffer(6) ]]) + constant VertexTriWideVecInstance *wideVecInsts [[ buffer(wideVectorUBOCount + 3) ]]) { ProjVertexTriWideVecPerf outVert = { .position = discardPt, @@ -564,7 +562,7 @@ vertex ProjVertexTriWideVecPerf vertexTri_wideVecPerf( // Fragment shader that takes the back of the globe into account fragment float4 fragmentTri_wideVecPerf( ProjVertexTriWideVecPerf vert [[stage_in]], - constant Uniforms &uniforms [[ buffer(1) ]]) + constant Uniforms &uniforms [[ buffer(idWideVectorUniformsUBO) ]]) { float patternAlpha = 1.0; diff --git a/include/mbgl/shaders/raster_layer_ubo.hpp b/include/mbgl/shaders/raster_layer_ubo.hpp index 4e3c9a523c1..0e96d9c4713 100644 --- a/include/mbgl/shaders/raster_layer_ubo.hpp +++ b/include/mbgl/shaders/raster_layer_ubo.hpp @@ -6,24 +6,28 @@ namespace mbgl { namespace shaders { struct alignas(16) RasterDrawableUBO { - std::array matrix; + /* 0 */ std::array matrix; + /* 64 */ }; -static_assert(sizeof(RasterDrawableUBO) == 64); +static_assert(sizeof(RasterDrawableUBO) == 4 * 16); +/// Evaluated properties that do not depend on the tile struct alignas(16) RasterEvaluatedPropsUBO { - std::array spin_weights; - std::array tl_parent; - float scale_parent; - float buffer_scale; - float fade_t; - float opacity; - float brightness_low; - float brightness_high; - float saturation_factor; - float contrast_factor; - float pad1, pad2; + /* 0 */ std::array spin_weights; + /* 16 */ std::array tl_parent; + /* 24 */ float scale_parent; + /* 28 */ float buffer_scale; + /* 32 */ float fade_t; + /* 36 */ float opacity; + /* 40 */ float brightness_low; + /* 44 */ float brightness_high; + /* 48 */ float saturation_factor; + /* 52 */ float contrast_factor; + /* 56 */ float pad1; + /* 60 */ float pad2; + /* 64 */ }; -static_assert(sizeof(RasterEvaluatedPropsUBO) == 64); +static_assert(sizeof(RasterEvaluatedPropsUBO) == 4 * 16); } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/shader_defines.hpp b/include/mbgl/shaders/shader_defines.hpp index 997a41bc9bd..4efce8bf8fd 100644 --- a/include/mbgl/shaders/shader_defines.hpp +++ b/include/mbgl/shaders/shader_defines.hpp @@ -10,35 +10,29 @@ namespace shaders { // drawable UBOs enum { - idClippingMaskUBO = globalUBOCount, - clippingMaskUBOCount -}; - -enum { - idCommonUBO = globalUBOCount, - commonDrawableUBOCount + idBackgroundDrawableUBO = globalUBOCount, + backgroundDrawableUBOCount }; enum { idCircleDrawableUBO = globalUBOCount, - idCircleInterpolateUBO, circleDrawableUBOCount }; enum { - idBackgroundDrawableUBO = globalUBOCount, - backgroundDrawableUBOCount + idClippingMaskUBO = globalUBOCount, + clippingMaskDrawableUBOCount }; enum { - idCustomSymbolDrawableUBO = globalUBOCount, - idCustomSymbolParametersUBO, - customSymbolDrawableUBOCount + idCollisionDrawableUBO = globalUBOCount, + idCollisionTilePropsUBO, + collisionDrawableUBOCount }; enum { - idCollisionUBO = globalUBOCount, - collisionDrawableUBOCount + idCustomSymbolDrawableUBO = globalUBOCount, + customSymbolDrawableUBOCount }; enum { @@ -49,40 +43,47 @@ enum { enum { idFillDrawableUBO = globalUBOCount, idFillTilePropsUBO, - idFillInterpolateUBO, fillDrawableUBOCount }; enum { idFillExtrusionDrawableUBO = globalUBOCount, idFillExtrusionTilePropsUBO, - idFillExtrusionInterpolateUBO, fillExtrusionDrawableUBOCount }; enum { idHeatmapDrawableUBO = globalUBOCount, - idHeatmapInterpolateUBO, heatmapDrawableUBOCount }; +enum { + heatmapTextureDrawableUBOCount = globalUBOCount +}; + enum { idHillshadeDrawableUBO = globalUBOCount, + idHillshadeTilePropsUBO, hillshadeDrawableUBOCount }; enum { idHillshadePrepareDrawableUBO = globalUBOCount, + idHillshadePrepareTilePropsUBO, hillshadePrepareDrawableUBOCount }; enum { idLineDrawableUBO = globalUBOCount, - idLineInterpolationUBO, - idLineTilePropertiesUBO, + idLineTilePropsUBO, lineDrawableUBOCount }; +enum { + idLocationIndicatorDrawableUBO = globalUBOCount, + locationIndicatorDrawableUBOCount +}; + enum { idRasterDrawableUBO = globalUBOCount, rasterDrawableUBOCount @@ -91,7 +92,6 @@ enum { enum { idSymbolDrawableUBO = globalUBOCount, idSymbolTilePropsUBO, - idSymbolInterpolateUBO, symbolDrawableUBOCount }; @@ -101,18 +101,20 @@ enum { wideVectorDrawableUBOCount }; -static constexpr auto layerUBOStartId = std::max({static_cast(circleDrawableUBOCount), - static_cast(backgroundDrawableUBOCount), - static_cast(customSymbolDrawableUBOCount), +static constexpr auto layerUBOStartId = std::max({static_cast(backgroundDrawableUBOCount), + static_cast(circleDrawableUBOCount), + static_cast(clippingMaskDrawableUBOCount), static_cast(collisionDrawableUBOCount), - static_cast(commonDrawableUBOCount), + static_cast(customSymbolDrawableUBOCount), static_cast(debugDrawableUBOCount), static_cast(fillDrawableUBOCount), static_cast(fillExtrusionDrawableUBOCount), static_cast(heatmapDrawableUBOCount), + static_cast(heatmapTextureDrawableUBOCount), static_cast(hillshadeDrawableUBOCount), static_cast(hillshadePrepareDrawableUBOCount), static_cast(lineDrawableUBOCount), + static_cast(locationIndicatorDrawableUBOCount), static_cast(rasterDrawableUBOCount), static_cast(symbolDrawableUBOCount), static_cast(wideVectorDrawableUBOCount)}); @@ -127,14 +129,30 @@ static constexpr auto maxUBOCountPerDrawable = layerUBOStartId - globalUBOCount; #define getLayerStartValue(packedValue) packedValue #endif +enum { + idBackgroundPropsUBO = getLayerStartValue(backgroundDrawableUBOCount), + backgroundUBOCount +}; + enum { idCircleEvaluatedPropsUBO = getLayerStartValue(circleDrawableUBOCount), circleUBOCount }; enum { - idBackgroundLayerUBO = getLayerStartValue(backgroundDrawableUBOCount), - backgroundUBOCount + clippingMaskUBOCount = getLayerStartValue(clippingMaskDrawableUBOCount) +}; + +enum { + collisionUBOCount = getLayerStartValue(collisionDrawableUBOCount) +}; + +enum { + customSymbolUBOCount = getLayerStartValue(customSymbolDrawableUBOCount) +}; + +enum { + debugUBOCount = getLayerStartValue(debugDrawableUBOCount) }; enum { @@ -153,7 +171,7 @@ enum { }; enum { - idHeatmapTexturePropsUBO = getLayerStartValue(globalUBOCount), + idHeatmapTexturePropsUBO = getLayerStartValue(heatmapTextureDrawableUBOCount), heatmapTextureUBOCount }; @@ -162,12 +180,20 @@ enum { hillshadeUBOCount }; +enum { + hillshadePrepareUBOCount = getLayerStartValue(hillshadePrepareDrawableUBOCount) +}; + enum { idLineEvaluatedPropsUBO = getLayerStartValue(lineDrawableUBOCount), idLineExpressionUBO, lineUBOCount }; +enum { + locationIndicatorUBOCount = getLayerStartValue(locationIndicatorDrawableUBOCount) +}; + enum { idRasterEvaluatedPropsUBO = getLayerStartValue(rasterDrawableUBOCount), rasterUBOCount @@ -178,18 +204,29 @@ enum { symbolUBOCount }; +enum { + wideVectorUBOCount = getLayerStartValue(wideVectorDrawableUBOCount) +}; + #undef getLayerStartValue -static constexpr auto maxUBOCountPerShader = std::max({static_cast(circleUBOCount), +static constexpr auto maxUBOCountPerShader = std::max({static_cast(backgroundUBOCount), + static_cast(circleUBOCount), static_cast(clippingMaskUBOCount), + static_cast(collisionUBOCount), + static_cast(customSymbolUBOCount), + static_cast(debugUBOCount), static_cast(fillUBOCount), static_cast(fillExtrusionUBOCount), static_cast(heatmapUBOCount), static_cast(heatmapTextureUBOCount), static_cast(hillshadeUBOCount), + static_cast(hillshadePrepareUBOCount), static_cast(lineUBOCount), + static_cast(locationIndicatorUBOCount), static_cast(rasterUBOCount), - static_cast(symbolUBOCount)}); + static_cast(symbolUBOCount), + static_cast(wideVectorUBOCount)}); static constexpr auto maxUBOCountPerLayer = maxUBOCountPerShader - layerUBOStartId; diff --git a/include/mbgl/shaders/shader_manifest.hpp b/include/mbgl/shaders/shader_manifest.hpp index 451eeecc935..79b6e38ea5c 100644 --- a/include/mbgl/shaders/shader_manifest.hpp +++ b/include/mbgl/shaders/shader_manifest.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -23,12 +24,13 @@ #include #include #include +#include +#include #include #include #include #include #include -#include #include #include #include diff --git a/include/mbgl/shaders/shader_source.hpp b/include/mbgl/shaders/shader_source.hpp index debb932ea86..167b95647f9 100644 --- a/include/mbgl/shaders/shader_source.hpp +++ b/include/mbgl/shaders/shader_source.hpp @@ -14,8 +14,7 @@ enum class BuiltIn { CircleShader, CollisionBoxShader, CollisionCircleShader, - CommonShader, - CommonTexturedShader, + CustomSymbolIconShader, DebugShader, FillShader, FillOutlineShader, @@ -31,12 +30,13 @@ enum class BuiltIn { LineShader, LineGradientShader, LinePatternShader, + LocationIndicatorShader, + LocationIndicatorTexturedShader, LineSDFShader, RasterShader, SymbolIconShader, SymbolSDFIconShader, SymbolTextAndIconShader, - CustomSymbolIconShader, WideVectorShader, Prelude, BackgroundProgram, diff --git a/include/mbgl/shaders/symbol_layer_ubo.hpp b/include/mbgl/shaders/symbol_layer_ubo.hpp index ca1f6917397..6ede60798d5 100644 --- a/include/mbgl/shaders/symbol_layer_ubo.hpp +++ b/include/mbgl/shaders/symbol_layer_ubo.hpp @@ -12,40 +12,34 @@ struct alignas(16) SymbolDrawableUBO { /* 192 */ std::array texsize; /* 200 */ std::array texsize_icon; - - /* 208 */ float gamma_scale; + + /* 208 */ /*bool*/ int is_text_prop; /* 212 */ /*bool*/ int rotate_symbol; - - /* 216 */ std::array pad; - /* 224 */ + /* 216 */ /*bool*/ int pitch_with_map; + /* 220 */ /*bool*/ int is_size_zoom_constant; + /* 224 */ /*bool*/ int is_size_feature_constant; + + /* 228 */ float size_t; + /* 232 */ float size; + + // Interpolations + /* 236 */ float fill_color_t; + /* 240 */ float halo_color_t; + /* 244 */ float opacity_t; + /* 248 */ float halo_width_t; + /* 252 */ float halo_blur_t; + /* 256 */ }; -static_assert(sizeof(SymbolDrawableUBO) == 14 * 16); +static_assert(sizeof(SymbolDrawableUBO) == 16 * 16); -/// Evaluated properties that depend on the tile struct alignas(16) SymbolTilePropsUBO { /* 0 */ /*bool*/ int is_text; /* 4 */ /*bool*/ int is_halo; - /* 8 */ /*bool*/ int pitch_with_map; - /* 12 */ /*bool*/ int is_size_zoom_constant; - /* 16 */ /*bool*/ int is_size_feature_constant; - /* 20 */ float size_t; - /* 24 */ float size; - /* 28 */ float padding; - /* 32 */ -}; -static_assert(sizeof(SymbolTilePropsUBO) == 2 * 16); - -/// Attribute interpolations -struct alignas(16) SymbolInterpolateUBO { - /* 0 */ float fill_color_t; - /* 4 */ float halo_color_t; - /* 8 */ float opacity_t; - /* 12 */ float halo_width_t; - /* 16 */ float halo_blur_t; - /* 20 */ float pad1, pad2, pad3; - /* 32 */ + /* 8 */ float gamma_scale; + /* 12 */ float pad1; + /* 16 */ }; -static_assert(sizeof(SymbolInterpolateUBO) == 32); +static_assert(sizeof(SymbolTilePropsUBO) == 16); /// Evaluated properties that do not depend on the tile struct alignas(16) SymbolEvaluatedPropsUBO { diff --git a/include/mbgl/shaders/vulkan/background.hpp b/include/mbgl/shaders/vulkan/background.hpp index 63a760df8b5..81989d916da 100644 --- a/include/mbgl/shaders/vulkan/background.hpp +++ b/include/mbgl/shaders/vulkan/background.hpp @@ -13,7 +13,7 @@ struct ShaderSource { static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -32,11 +32,13 @@ void main() { static constexpr auto fragment = R"( layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundLayerUBO { +layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPropsUBO { vec4 color; float opacity; - float pad1, pad2, pad3; -} layer; + float pad1; + float pad2; + float pad3; +} props; void main() { @@ -45,7 +47,7 @@ void main() { return; #endif - out_color = layer.color * layer.opacity; + out_color = props.color * props.opacity; } )"; }; @@ -68,10 +70,12 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform BackgroundPatternDrawa vec2 pixel_coord_upper; vec2 pixel_coord_lower; float tile_units_to_pixels; - float pad1, pad2, pad3; + float pad1; + float pad2; + float pad3; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternLayerUBO { +layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternPropsUBO { vec2 pattern_tl_a; vec2 pattern_br_a; vec2 pattern_tl_b; @@ -82,7 +86,7 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternLayerUBO { float scale_b; float mix; float opacity; -} layer; +} props; layout(location = 0) out vec2 frag_pos_a; layout(location = 1) out vec2 frag_pos_b; @@ -91,12 +95,12 @@ void main() { frag_pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, - layer.scale_a * layer.pattern_size_a, + props.scale_a * props.pattern_size_a, drawable.tile_units_to_pixels, in_position); frag_pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, - layer.scale_b * layer.pattern_size_b, + props.scale_b * props.pattern_size_b, drawable.tile_units_to_pixels, in_position); @@ -122,7 +126,7 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternLayerUBO { float scale_b; float mix; float opacity; -} layer; +} props; layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; @@ -133,17 +137,17 @@ void main() { return; #endif - const vec2 texsize = global.pattern_atlas_texsize; + const vec2 texsize = paintParams.pattern_atlas_texsize; const vec2 imagecoord = mod(frag_pos_a, 1.0); - const vec2 pos = mix(layer.pattern_tl_a / texsize, layer.pattern_br_a / texsize, imagecoord); + const vec2 pos = mix(props.pattern_tl_a / texsize, props.pattern_br_a / texsize, imagecoord); const vec4 color1 = texture(image_sampler, pos); const vec2 imagecoord_b = mod(frag_pos_b, 1.0); - const vec2 pos2 = mix(layer.pattern_tl_b / texsize, layer.pattern_br_b / texsize, imagecoord_b); + const vec2 pos2 = mix(props.pattern_tl_b / texsize, props.pattern_br_b / texsize, imagecoord_b); const vec4 color2 = texture(image_sampler, pos2); - out_color = mix(color1, color2, layer.mix) * layer.opacity; + out_color = mix(color1, color2, props.mix) * props.opacity; } )"; }; diff --git a/include/mbgl/shaders/vulkan/circle.hpp b/include/mbgl/shaders/vulkan/circle.hpp index 0adafd5d97d..7d7198f3a61 100644 --- a/include/mbgl/shaders/vulkan/circle.hpp +++ b/include/mbgl/shaders/vulkan/circle.hpp @@ -10,10 +10,10 @@ template <> struct ShaderSource { static constexpr const char* name = "CircleShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -50,10 +50,7 @@ layout(location = 7) in vec2 in_stroke_opacity; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CircleDrawableUBO { mat4 matrix; vec2 extrude_scale; - vec2 padding; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CircleInterpolateUBO { + // Interpolations float color_t; float radius_t; float blur_t; @@ -61,8 +58,10 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CircleInterpolateUBO { float stroke_color_t; float stroke_width_t; float stroke_opacity_t; - float pad1_; -} interp; + float pad1; + float pad2; + float pad3; +} drawable; layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO { vec4 color; @@ -74,7 +73,7 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO { float stroke_opacity; bool scale_with_map; bool pitch_with_map; - float padding; + float pad1; } props; layout(location = 0) out vec2 frag_extrude; @@ -113,13 +112,13 @@ void main() { #if defined(HAS_UNIFORM_u_radius) const float radius = props.radius; #else - const float radius = unpack_mix_float(in_radius, interp.radius_t); + const float radius = unpack_mix_float(in_radius, drawable.radius_t); #endif #if defined(HAS_UNIFORM_u_stroke_width) const float stroke_width = props.stroke_width; #else - const float stroke_width = unpack_mix_float(in_stroke_width, interp.stroke_width_t); + const float stroke_width = unpack_mix_float(in_stroke_width, drawable.stroke_width_t); #endif // unencode the extrusion vector that we snuck into the a_pos vector @@ -139,14 +138,14 @@ void main() { // whole circle based on the pitch scaling effect at its central point const vec4 projected_center = drawable.matrix * vec4(circle_center, 0, 1); corner_position += scaled_extrude * (radius + stroke_width) * - (projected_center.w / global.camera_to_center_distance); + (projected_center.w / paintParams.camera_to_center_distance); } gl_Position = drawable.matrix * vec4(corner_position, 0, 1); } else { gl_Position = drawable.matrix * vec4(circle_center, 0, 1); - const float factor = props.scale_with_map ? global.camera_to_center_distance : gl_Position.w; + const float factor = props.scale_with_map ? paintParams.camera_to_center_distance : gl_Position.w; gl_Position.xy += scaled_extrude * (radius + stroke_width) * factor; } @@ -160,7 +159,7 @@ void main() { frag_extrude = extrude; #if !defined(HAS_UNIFORM_u_color) - frag_color = unpack_mix_color(in_color, interp.color_t); + frag_color = unpack_mix_color(in_color, drawable.color_t); #endif #if !defined(HAS_UNIFORM_u_radius) @@ -168,15 +167,15 @@ void main() { #endif #if !defined(HAS_UNIFORM_u_blur) - frag_blur = unpack_mix_float(in_blur, interp.blur_t); + frag_blur = unpack_mix_float(in_blur, drawable.blur_t); #endif #if !defined(HAS_UNIFORM_u_opacity) - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif #if !defined(HAS_UNIFORM_u_stroke_color) - frag_stroke_color = unpack_mix_color(in_stroke_color, interp.stroke_color_t); + frag_stroke_color = unpack_mix_color(in_stroke_color, drawable.stroke_color_t); #endif #if !defined(HAS_UNIFORM_u_stroke_width) @@ -184,7 +183,7 @@ void main() { #endif #if !defined(HAS_UNIFORM_u_stroke_opacity) - frag_stroke_opacity = unpack_mix_float(in_stroke_opacity, interp.stroke_opacity_t); + frag_stroke_opacity = unpack_mix_float(in_stroke_opacity, drawable.stroke_opacity_t); #endif } )"; @@ -234,7 +233,7 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO { float stroke_opacity; bool scale_with_map; bool pitch_with_map; - float padding; + float pad1; } props; void main() { diff --git a/include/mbgl/shaders/vulkan/clipping_mask.hpp b/include/mbgl/shaders/vulkan/clipping_mask.hpp index 7a803fe087f..d5b3ce9f171 100644 --- a/include/mbgl/shaders/vulkan/clipping_mask.hpp +++ b/include/mbgl/shaders/vulkan/clipping_mask.hpp @@ -16,10 +16,10 @@ template <> struct ShaderSource { static constexpr const char* name = "ClippingMaskProgram"; - static constexpr std::array uniforms{}; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( layout(location = 0) in ivec2 position; diff --git a/include/mbgl/shaders/vulkan/collision.hpp b/include/mbgl/shaders/vulkan/collision.hpp index d511ead2dd0..3ebdf230f7a 100644 --- a/include/mbgl/shaders/vulkan/collision.hpp +++ b/include/mbgl/shaders/vulkan/collision.hpp @@ -10,10 +10,10 @@ template <> struct ShaderSource { static constexpr const char* name = "CollisionBoxShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -23,12 +23,15 @@ layout(location = 2) in ivec2 in_extrude; layout(location = 3) in uvec2 in_placed; layout(location = 4) in vec2 in_shift; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionBoxUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionDrawableUBO { mat4 matrix; +} drawable; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CollisionTilePropsUBO { vec2 extrude_scale; float overscale_factor; float pad1; -} drawable; +} tileProps; layout(location = 0) out float frag_placed; layout(location = 1) out float frag_notUsed; @@ -38,12 +41,12 @@ void main() { vec4 projectedPoint = drawable.matrix * vec4(in_anchor_position, 0.0, 1.0); float camera_to_anchor_distance = projectedPoint.w; float collision_perspective_ratio = clamp( - 0.5 + 0.5 * (global.camera_to_center_distance / camera_to_anchor_distance), + 0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance), 0.0, // Prevents oversized near-field boxes in pitched/overzoomed tiles 4.0); gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0); - gl_Position.xy += (in_extrude + in_shift) * drawable.extrude_scale * gl_Position.w * collision_perspective_ratio; + gl_Position.xy += (in_extrude + in_shift) * tileProps.extrude_scale * gl_Position.w * collision_perspective_ratio; applySurfaceTransform(); frag_placed = in_placed.x; @@ -58,13 +61,6 @@ layout(location = 1) in float frag_notUsed; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionBoxUBO { - mat4 matrix; - vec2 extrude_scale; - float overscale_factor; - float pad1; -} drawable; - void main() { float alpha = 0.5; @@ -91,10 +87,10 @@ template <> struct ShaderSource { static constexpr const char* name = "CollisionCircleShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -103,12 +99,15 @@ layout(location = 1) in ivec2 in_anchor_position; layout(location = 2) in ivec2 in_extrude; layout(location = 3) in uvec2 in_placed; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionCircleUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionDrawableUBO { mat4 matrix; +} drawable; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CollisionTilePropsUBO { vec2 extrude_scale; float overscale_factor; float pad1; -} drawable; +} tileProps; layout(location = 0) out float frag_placed; layout(location = 1) out float frag_notUsed; @@ -121,20 +120,20 @@ void main() { vec4 projectedPoint = drawable.matrix * vec4(in_anchor_position, 0, 1); float camera_to_anchor_distance = projectedPoint.w; float collision_perspective_ratio = clamp( - 0.5 + 0.5 * (global.camera_to_center_distance / camera_to_anchor_distance), + 0.5 + 0.5 * (paintParams.camera_to_center_distance / camera_to_anchor_distance), 0.0, // Prevents oversized near-field circles in pitched/overzoomed tiles 4.0); float padding_factor = 1.2; // Pad the vertices slightly to make room for anti-alias blur gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0); - gl_Position.xy += in_extrude * drawable.extrude_scale * padding_factor * gl_Position.w * collision_perspective_ratio; + gl_Position.xy += in_extrude * tileProps.extrude_scale * padding_factor * gl_Position.w * collision_perspective_ratio; applySurfaceTransform(); frag_placed = in_placed.x; frag_notUsed = in_placed.y; frag_radius = abs(float(in_extrude.y)); // We don't pitch the circles, so both units of the extrusion vector are equal in magnitude to the radius frag_extrude = in_extrude * padding_factor; - frag_extrude_scale = drawable.extrude_scale * global.camera_to_center_distance * collision_perspective_ratio; + frag_extrude_scale = tileProps.extrude_scale * paintParams.camera_to_center_distance * collision_perspective_ratio; } )"; @@ -148,12 +147,11 @@ layout(location = 4) in vec2 frag_extrude_scale; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionCircleUBO { - mat4 matrix; +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CollisionTilePropsUBO { vec2 extrude_scale; float overscale_factor; float pad1; -} drawable; +} tileProps; void main() { @@ -174,7 +172,7 @@ void main() { float extrude_scale_length = length(frag_extrude_scale); float extrude_length = length(frag_extrude) * extrude_scale_length; - float stroke_width = 15.0 * extrude_scale_length / drawable.overscale_factor; + float stroke_width = 15.0 * extrude_scale_length / tileProps.overscale_factor; float radius = frag_radius * extrude_scale_length; float distance_to_edge = abs(extrude_length - radius); diff --git a/include/mbgl/shaders/vulkan/common.hpp b/include/mbgl/shaders/vulkan/common.hpp index cb0f13a804e..10c395d245d 100644 --- a/include/mbgl/shaders/vulkan/common.hpp +++ b/include/mbgl/shaders/vulkan/common.hpp @@ -80,19 +80,19 @@ layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO { float symbol_fade_change; float aspect_ratio; float pixel_ratio; - float zoom; + float map_zoom; float pad1; -} global; +} paintParams; #ifdef USE_SURFACE_TRANSFORM -layout(set = GLOBAL_SET_INDEX, binding = 1) uniform PlatformParamsUBO { +layout(set = GLOBAL_SET_INDEX, binding = 1) uniform GlobalPlatformParamsUBO { mat2 rotation; -} platform; +} platformParams; #endif void applySurfaceTransform() { #ifdef USE_SURFACE_TRANSFORM - gl_Position.xy = platform.rotation * gl_Position.xy; + gl_Position.xy = platformParams.rotation * gl_Position.xy; #endif gl_Position.y *= -1.0; @@ -118,89 +118,12 @@ layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO { float symbol_fade_change; float aspect_ratio; float pixel_ratio; - float zoom; + float map_zoom; float pad1; -} global; +} paintParams; )"; }; -template <> -struct ShaderSource { - static constexpr const char* name = "CommonShader"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; - - static constexpr auto vertex = R"( -layout(location = 0) in vec2 in_position; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CommonUBO { - mat4 matrix; - vec4 color; -} ubo; - -void main() { - gl_Position = ubo.matrix * vec4(in_position, 0, 1); - applySurfaceTransform(); -} -)"; - - static constexpr auto fragment = R"( -layout(location = 0) out vec4 out_color; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CommonUBO { - mat4 matrix; - vec4 color; -} ubo; - -void main() { - out_color = ubo.color; -} -)"; -}; - -template <> -struct ShaderSource { - static constexpr const char* name = "CommonTexturedShader"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto vertex = R"( -layout(location = 0) in vec2 in_position; -layout(location = 1) in vec2 in_texcoord; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CommonUBO { - mat4 matrix; - vec4 color; -} ubo; - -layout(location = 0) out vec2 frag_uv; - -void main() { - gl_Position = ubo.matrix * vec4(in_position, 0, 1); - applySurfaceTransform(); - - frag_uv = in_texcoord; -} -)"; - - static constexpr auto fragment = R"( -layout(location = 0) in vec2 frag_uv; -layout(location = 0) out vec4 out_color; - -layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; - -void main() { - out_color = texture(image_sampler, frag_uv); -} -)"; -}; - } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp b/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp new file mode 100644 index 00000000000..a3030b8822d --- /dev/null +++ b/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp @@ -0,0 +1,101 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace shaders { + +template <> +struct ShaderSource { + static constexpr const char* name = "CustomSymbolIconShader"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto vertex = R"( + +layout(location = 0) in vec2 in_position; +layout(location = 1) in vec2 in_tex; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CustomSymbolIconDrawableUBO { + mat4 matrix; + vec2 extrude_scale; + vec2 anchor; + float angle_degrees; + bool scale_with_map; + bool pitch_with_map; + float camera_to_center_distance; + float aspect_ratio; + float pad1; + float pad2; + float pad3; +} drawable; + +layout(location = 0) out vec2 frag_tex; + +vec2 rotateVec2(vec2 v, float angle) { + float cosA = cos(angle); + float sinA = sin(angle); + return vec2(v.x * cosA - v.y * sinA, v.x * sinA + v.y * cosA); +} + +vec2 ellipseRotateVec2(vec2 v, float angle, float radiusRatio /* A/B */) { + float cosA = cos(angle); + float sinA = sin(angle); + float invRatio = 1.0 / radiusRatio; + return vec2(v.x * cosA - radiusRatio * v.y * sinA, invRatio * v.x * sinA + v.y * cosA); +} + +void main() { + const vec2 extrude = mod(in_position, 2.0) * 2.0 - 1.0; + const vec2 anchor = (drawable.anchor - vec2(0.5, 0.5)) * 2.0; + const vec2 center = floor(in_position * 0.5); + const float angle = radians(-drawable.angle_degrees); + vec2 corner = extrude - anchor; + + vec4 position; + if (drawable.pitch_with_map) { + if (drawable.scale_with_map) { + corner *= drawable.extrude_scale; + } else { + vec4 projected_center = drawable.matrix * vec4(center, 0, 1); + corner *= drawable.extrude_scale * (projected_center.w / drawable.camera_to_center_distance); + } + corner = center + rotateVec2(corner, angle); + position = drawable.matrix * vec4(corner, 0, 1); + } else { + position = drawable.matrix * vec4(center, 0, 1); + const float factor = drawable.scale_with_map ? drawable.camera_to_center_distance : position.w; + position.xy += ellipseRotateVec2(corner * drawable.extrude_scale * factor, angle, drawable.aspect_ratio); + } + + gl_Position = position; + applySurfaceTransform(); + + frag_tex = in_tex; +} +)"; + + static constexpr auto fragment = R"( +layout(location = 0) in vec2 frag_tex; +layout(location = 0) out vec4 out_color; + +layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; + +void main() { + +#if defined(OVERDRAW_INSPECTOR) + out_color = vec4(1.0); + return; +#endif + + out_color = texture(image_sampler, frag_tex); +} +)"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/debug.hpp b/include/mbgl/shaders/vulkan/debug.hpp index bbd3e9e7652..992bf6745ed 100644 --- a/include/mbgl/shaders/vulkan/debug.hpp +++ b/include/mbgl/shaders/vulkan/debug.hpp @@ -23,7 +23,9 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform DebugUBO { mat4 matrix; vec4 color; float overlay_scale; - float pad1, pad2, pad3; + float pad1; + float pad2; + float pad3; } debug; layout(location = 0) out vec2 frag_uv; @@ -47,7 +49,9 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform DebugUBO { mat4 matrix; vec4 color; float overlay_scale; - float pad1, pad2, pad3; + float pad1; + float pad2; + float pad3; } debug; layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; diff --git a/include/mbgl/shaders/vulkan/fill.hpp b/include/mbgl/shaders/vulkan/fill.hpp index 63fc4f2b951..93f71950593 100644 --- a/include/mbgl/shaders/vulkan/fill.hpp +++ b/include/mbgl/shaders/vulkan/fill.hpp @@ -10,10 +10,10 @@ template <> struct ShaderSource { static constexpr const char* name = "FillShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -29,12 +29,12 @@ layout(location = 2) in vec2 in_opacity; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillDrawableUBO { mat4 matrix; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillInterpolateUBO { + // Interpolations float color_t; float opacity_t; -} interp; + float pad1; + float pad2; +} drawable; #if !defined(HAS_UNIFORM_u_color) layout(location = 0) out vec4 frag_color; @@ -47,11 +47,11 @@ layout(location = 1) out lowp float frag_opacity; void main() { #if !defined(HAS_UNIFORM_u_color) - frag_color = vec4(unpack_mix_color(in_color, interp.color_t)); + frag_color = vec4(unpack_mix_color(in_color, drawable.color_t)); #endif #if !defined(HAS_UNIFORM_u_opacity) - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0); @@ -103,10 +103,10 @@ template <> struct ShaderSource { static constexpr const char* name = "FillOutlineShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -120,14 +120,14 @@ layout(location = 1) in vec4 in_color; layout(location = 2) in vec2 in_opacity; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillOutlineDrawableUBO { mat4 matrix; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillInterpolateUBO { - float color_t; + // Interpolations + float outline_color_t; float opacity_t; -} interp; + float pad1; + float pad2; +} drawable; #if !defined(HAS_UNIFORM_u_outline_color) layout(location = 0) out vec4 frag_color; @@ -142,17 +142,17 @@ layout(location = 2) out vec2 frag_position; void main() { #if !defined(HAS_UNIFORM_u_outline_color) - frag_color = vec4(unpack_mix_color(in_color, interp.color_t)); + frag_color = vec4(unpack_mix_color(in_color, drawable.outline_color_t)); #endif #if !defined(HAS_UNIFORM_u_opacity) - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0); applySurfaceTransform(); - frag_position = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * global.world_size; + frag_position = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * paintParams.world_size; } )"; @@ -209,7 +209,7 @@ template <> struct ShaderSource { static constexpr const char* name = "FillPatternShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -234,21 +234,20 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillPatternDrawableUBO mat4 matrix; vec2 pixel_coord_upper; vec2 pixel_coord_lower; - vec2 texsize; float tile_ratio; - float pad; + // Interpolations + float pattern_from_t; + float pattern_to_t; + float opacity_t; } drawable; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillPatternTilePropsUBO { vec4 pattern_from; vec4 pattern_to; -} tile; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform FillPatternInterpolateUBO { - float pattern_from_t; - float pattern_to_t; - float opacity_t; -} interp; + vec2 texsize; + float pad1; + float pad2; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { vec4 color; @@ -277,19 +276,19 @@ layout(location = 4) out lowp float frag_opacity; void main() { #if defined(HAS_UNIFORM_u_pattern_from) - const vec4 frag_pattern_from = tile.pattern_from; + const vec4 frag_pattern_from = tileProps.pattern_from; #else frag_pattern_from = in_pattern_from; #endif #if defined(HAS_UNIFORM_u_pattern_to) - const vec4 frag_pattern_to = tile.pattern_to; + const vec4 frag_pattern_to = tileProps.pattern_to; #else frag_pattern_to = in_pattern_to; #endif #if !defined(HAS_UNIFORM_u_opacity) - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif const vec2 pattern_tl_a = frag_pattern_from.xy; @@ -297,7 +296,7 @@ void main() { const vec2 pattern_tl_b = frag_pattern_to.xy; const vec2 pattern_br_b = frag_pattern_to.zw; - const float pixelRatio = global.pixel_ratio; + const float pixelRatio = paintParams.pixel_ratio; const float tileZoomRatio = drawable.tile_ratio; const float fromScale = props.from_scale; const float toScale = props.to_scale; @@ -332,19 +331,13 @@ layout(location = 4) in lowp float frag_opacity; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillPatternDrawableUBO { - mat4 matrix; - vec2 pixel_coord_upper; - vec2 pixel_coord_lower; - vec2 texsize; - float tile_ratio; - float pad; -} drawable; - layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillPatternTilePropsUBO { vec4 pattern_from; vec4 pattern_to; -} tile; + vec2 texsize; + float pad1; + float pad2; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { vec4 color; @@ -365,13 +358,13 @@ void main() { #endif #if defined(HAS_UNIFORM_u_pattern_from) - const vec4 pattern_from = tile.pattern_from; + const vec4 pattern_from = tileProps.pattern_from; #else const vec4 pattern_from = frag_pattern_from; #endif #if defined(HAS_UNIFORM_u_pattern_to) - const vec4 pattern_to = tile.pattern_to; + const vec4 pattern_to = tileProps.pattern_to; #else const vec4 pattern_to = frag_pattern_to; #endif @@ -388,11 +381,11 @@ void main() { const vec2 pattern_br_b = pattern_to.zw; const vec2 imagecoord = mod(frag_pos_a, 1.0); - const vec2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord); + const vec2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord); const vec4 color1 = texture(image0_sampler, pos); const vec2 imagecoord_b = mod(frag_pos_b, 1.0); - const vec2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b); + const vec2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b); const vec4 color2 = texture(image0_sampler, pos2); out_color = mix(color1, color2, props.fade) * opacity; @@ -404,7 +397,7 @@ template <> struct ShaderSource { static constexpr const char* name = "FillOutlinePatternShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -429,21 +422,20 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillOutlinePatternDraw mat4 matrix; vec2 pixel_coord_upper; vec2 pixel_coord_lower; - vec2 texsize; float tile_ratio; - float pad; + // Interpolations + float pattern_from_t; + float pattern_to_t; + float opacity_t; } drawable; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillOutlinePatternTilePropsUBO { vec4 pattern_from; vec4 pattern_to; -} tile; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform FillOutlinePatternInterpolateUBO { - float pattern_from_t; - float pattern_to_t; - float opacity_t; -} interp; + vec2 texsize; + float pad1; + float pad2; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { vec4 color; @@ -473,19 +465,19 @@ layout(location = 5) out lowp float frag_opacity; void main() { #if defined(HAS_UNIFORM_u_pattern_from) - const vec4 frag_pattern_from = tile.pattern_from; + const vec4 frag_pattern_from = tileProps.pattern_from; #else frag_pattern_from = in_pattern_from; #endif #if defined(HAS_UNIFORM_u_pattern_to) - const vec4 frag_pattern_to = tile.pattern_to; + const vec4 frag_pattern_to = tileProps.pattern_to; #else frag_pattern_to = in_pattern_to; #endif #if !defined(HAS_UNIFORM_u_opacity) - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif const vec2 pattern_tl_a = frag_pattern_from.xy; @@ -493,7 +485,7 @@ void main() { const vec2 pattern_tl_b = frag_pattern_to.xy; const vec2 pattern_br_b = frag_pattern_to.zw; - const float pixelRatio = global.pixel_ratio; + const float pixelRatio = paintParams.pixel_ratio; const float tileZoomRatio = drawable.tile_ratio; const float fromScale = props.from_scale; const float toScale = props.to_scale; @@ -507,7 +499,7 @@ void main() { frag_pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, position2), frag_pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, position2), - frag_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * global.world_size; + frag_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * paintParams.world_size; } )"; @@ -531,19 +523,13 @@ layout(location = 5) in lowp float frag_opacity; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillOutlinePatternDrawableUBO { - mat4 matrix; - vec2 pixel_coord_upper; - vec2 pixel_coord_lower; - vec2 texsize; - float tile_ratio; - float pad; -} drawable; - layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillOutlinePatternTilePropsUBO { vec4 pattern_from; vec4 pattern_to; -} tile; + vec2 texsize; + float pad1; + float pad2; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { vec4 color; @@ -564,13 +550,13 @@ void main() { #endif #if defined(HAS_UNIFORM_u_pattern_from) - const vec4 pattern_from = tile.pattern_from; + const vec4 pattern_from = tileProps.pattern_from; #else const vec4 pattern_from = frag_pattern_from; #endif #if defined(HAS_UNIFORM_u_pattern_to) - const vec4 pattern_to = tile.pattern_to; + const vec4 pattern_to = tileProps.pattern_to; #else const vec4 pattern_to = frag_pattern_to; #endif @@ -587,11 +573,11 @@ void main() { const vec2 pattern_br_b = pattern_to.zw; const vec2 imagecoord = mod(frag_pos_a, 1.0); - const vec2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord); + const vec2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord); const vec4 color1 = texture(image0_sampler, pos); const vec2 imagecoord_b = mod(frag_pos_b, 1.0); - const vec2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b); + const vec2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b); const vec4 color2 = texture(image0_sampler, pos2); const float dist = length(frag_pos - gl_FragCoord.xy); @@ -609,7 +595,7 @@ struct ShaderSource uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -619,7 +605,9 @@ layout(location = 1) in uvec4 in_data; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillOutlineTriangulatedDrawableUBO { mat4 matrix; float ratio; - float pad1, pad2, pad3; + float pad1, + float pad2 + float pad3; } drawable; layout(location = 0) out float frag_width2; @@ -657,7 +645,7 @@ void main() { // calculate how much the perspective view squishes or stretches the extrude float extrude_length_without_perspective = length(dist); - float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * global.units_to_pixels); + float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * paintParams.units_to_pixels); frag_width2 = outset; frag_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective; @@ -701,395 +689,5 @@ void main() { )"; }; -template <> -struct ShaderSource { - static constexpr const char* name = "FillExtrusionShader"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; - - static constexpr auto vertex = R"( - -layout(location = 0) in ivec2 in_position; -layout(location = 1) in ivec4 in_normal_ed; - -#if !defined(HAS_UNIFORM_u_color) -layout(location = 2) in vec4 in_color; -#endif - -#if !defined(HAS_UNIFORM_u_base) -layout(location = 3) in vec2 in_base; -#endif - -#if !defined(HAS_UNIFORM_u_height) -layout(location = 4) in vec2 in_height; -#endif - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableUBO { - mat4 matrix; - vec2 texsize; - vec2 pixel_coord_upper; - vec2 pixel_coord_lower; - float height_factor; - float tile_ratio; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform FillExtrusionInterpolateUBO { - float base_t; - float height_t; - float color_t; - float pattern_from_t; - float pattern_to_t; - float pad1, pad2, pad3; -} interp; - -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { - vec4 color; - vec4 light_color_pad; - vec4 light_position_base; - float height; - float light_intensity; - float vertical_gradient; - float opacity; - float fade; - float from_scale; - float to_scale; - float pad2; -} props; - -layout(location = 0) out mediump vec4 frag_color; - -void main() { - -#if defined(HAS_UNIFORM_u_base) - const float base = props.light_position_base.w; -#else - const float base = max(unpack_mix_float(in_base, interp.base_t), 0.0); -#endif - -#if defined(HAS_UNIFORM_u_height) - const float height = props.height; -#else - const float height = max(unpack_mix_float(in_height, interp.height_t), 0.0); -#endif - -#if defined(HAS_UNIFORM_u_color) - vec4 color = props.color; -#else - vec4 color = unpack_mix_color(in_color, interp.color_t); -#endif - - const vec3 normal = in_normal_ed.xyz; - const float t = mod(normal.x, 2.0); - const float z = t != 0.0 ? height : base; - - gl_Position = drawable.matrix * vec4(in_position, z, 1.0); - applySurfaceTransform(); - -#if defined(OVERDRAW_INSPECTOR) - frag_color = vec4(1.0); - return; -#endif - - // Relative luminance (how dark/bright is the surface color?) - const float luminance = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722; - - vec4 vcolor = vec4(0.0, 0.0, 0.0, 1.0); - - // Add slight ambient lighting so no extrusions are totally black - color += vec4(0.03, 0.03, 0.03, 1.0); - - // Calculate cos(theta), where theta is the angle between surface normal and diffuse light ray - const float directionalFraction = clamp(dot(normal / 16384.0, props.light_position_base.xyz), 0.0, 1.0); - - // Adjust directional so that the range of values for highlight/shading is - // narrower with lower light intensity and with lighter/brighter surface colors - const float minDirectional = 1.0 - props.light_intensity; - const float maxDirectional = max(1.0 - luminance + props.light_intensity, 1.0); - float directional = mix(minDirectional, maxDirectional, directionalFraction); - - // Add gradient along z axis of side surfaces - if (normal.y != 0.0) { - // This avoids another branching statement, but multiplies by a constant of 0.84 if no - // vertical gradient, and otherwise calculates the gradient based on base + height - // TODO: If we're optimizing to the level of avoiding branches, we should pre-compute - // the square root when height is a uniform. - const float fMin = mix(0.7, 0.98, 1.0 - props.light_intensity); - const float factor = clamp((t + base) * pow(height / 150.0, 0.5), fMin, 1.0); - directional *= (1.0 - props.vertical_gradient) + (props.vertical_gradient * factor); - } - - // Assign final color based on surface + ambient light color, diffuse light directional, - // and light color with lower bounds adjusted to hue of light so that shading is tinted - // with the complementary (opposite) color to the light color - const vec3 light_color = props.light_color_pad.rgb; - const vec3 minLight = mix(vec3(0.0), vec3(0.3), 1.0 - light_color.rgb); - vcolor += vec4(clamp(color.rgb * directional * light_color.rgb, minLight, vec3(1.0)), 0.0); - - frag_color = vcolor * props.opacity; -} -)"; - - static constexpr auto fragment = R"( - -layout(location = 0) in vec4 frag_color; -layout(location = 0) out vec4 out_color; - -void main() { - out_color = frag_color; -} -)"; -}; - -template <> -struct ShaderSource { - static constexpr const char* name = "FillExtrusionPatternShader"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto vertex = R"( - -layout(location = 0) in ivec2 in_position; -layout(location = 1) in ivec4 in_normal_ed; - -#if !defined(HAS_UNIFORM_u_base) -layout(location = 2) in vec2 in_base; -#endif - -#if !defined(HAS_UNIFORM_u_height) -layout(location = 3) in vec2 in_height; -#endif - -#if !defined(HAS_UNIFORM_u_pattern_from) -layout(location = 4) in uvec4 in_pattern_from; -#endif - -#if !defined(HAS_UNIFORM_u_pattern_to) -layout(location = 5) in uvec4 in_pattern_to; -#endif - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableUBO { - mat4 matrix; - vec2 texsize; - vec2 pixel_coord_upper; - vec2 pixel_coord_lower; - float height_factor; - float tile_ratio; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillExtrusionTilePropsUBO { - vec4 pattern_from; - vec4 pattern_to; -} tile; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform FillExtrusionInterpolateUBO { - float base_t; - float height_t; - float color_t; - float pattern_from_t; - float pattern_to_t; - float pad1, pad2, pad3; -} interp; - -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { - vec4 color; - vec4 light_color_pad; - vec4 light_position_base; - float height; - float light_intensity; - float vertical_gradient; - float opacity; - float fade; - float from_scale; - float to_scale; - float pad2; -} props; - -layout(location = 0) out mediump vec4 frag_lighting; -layout(location = 1) out mediump vec2 frag_pos_a; -layout(location = 2) out mediump vec2 frag_pos_b; - -#if !defined(HAS_UNIFORM_u_pattern_from) -layout(location = 3) out mediump vec4 frag_pattern_from; -#endif - -#if !defined(HAS_UNIFORM_u_pattern_to) -layout(location = 4) out mediump vec4 frag_pattern_to; -#endif - -void main() { - -#if defined(HAS_UNIFORM_u_base) - const float base = props.light_position_base.w; -#else - const float base = max(unpack_mix_float(in_base, interp.base_t), 0.0); -#endif - -#if defined(HAS_UNIFORM_u_height) - const float height = props.height; -#else - const float height = max(unpack_mix_float(in_height, interp.height_t), 0.0); -#endif - - const vec3 normal = in_normal_ed.xyz; - const float edgedistance = in_normal_ed.w; - const float t = mod(normal.x, 2.0); - const float z = t != 0.0 ? height : base; - - gl_Position = drawable.matrix * vec4(in_position, z, 1.0); - applySurfaceTransform(); - -#if defined(OVERDRAW_INSPECTOR) - frag_color = vec4(1.0); - return; -#endif - -#if defined(HAS_UNIFORM_u_pattern_from) - const mediump vec4 pattern_from = tile.pattern_from; -#else - const mediump vec4 pattern_from = in_pattern_from; - frag_pattern_from = in_pattern_from; -#endif - -#if defined(HAS_UNIFORM_u_pattern_to) - const mediump vec4 pattern_to = tile.pattern_to; -#else - const mediump vec4 pattern_to = in_pattern_to; - frag_pattern_to = in_pattern_to; -#endif - - const vec2 pattern_tl_a = pattern_from.xy; - const vec2 pattern_br_a = pattern_from.zw; - const vec2 pattern_tl_b = pattern_to.xy; - const vec2 pattern_br_b = pattern_to.zw; - - const float pixelRatio = global.pixel_ratio; - const float tileZoomRatio = drawable.tile_ratio; - const float fromScale = props.from_scale; - const float toScale = props.to_scale; - - const vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); - const vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); - - const vec2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0 - ? vec2(in_position) // extrusion top - : vec2(edgedistance, z * drawable.height_factor); // extrusion side - - vec4 lighting = vec4(0.0, 0.0, 0.0, 1.0); - float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0); - directional = mix((1.0 - props.light_intensity), max((0.5 + props.light_intensity), 1.0), directional); - - if (normal.y != 0.0) { - // This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient, - // and otherwise calculates the gradient based on base + height - directional *= ( - (1.0 - props.vertical_gradient) + - (props.vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - props.light_intensity), 1.0))); - } - - lighting.rgb += clamp(directional * props.light_color_pad.rgb, mix(vec3(0.0), vec3(0.3), 1.0 - props.light_color_pad.rgb), vec3(1.0)); - lighting *= props.opacity; - - frag_lighting = lighting; - frag_pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos); - frag_pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos); - -#if !defined(HAS_UNIFORM_u_pattern_from) - frag_pattern_from = in_pattern_from; -#endif - -#if !defined(HAS_UNIFORM_u_pattern_to) - frag_pattern_to = in_pattern_to; -#endif -} -)"; - - static constexpr auto fragment = R"( - -layout(location = 0) in mediump vec4 frag_lighting; -layout(location = 1) in mediump vec2 frag_pos_a; -layout(location = 2) in mediump vec2 frag_pos_b; - -#if !defined(HAS_UNIFORM_u_pattern_from) -layout(location = 3) in mediump vec4 frag_pattern_from; -#endif - -#if !defined(HAS_UNIFORM_u_pattern_to) -layout(location = 4) in mediump vec4 frag_pattern_to; -#endif - -layout(location = 0) out vec4 out_color; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableUBO { - mat4 matrix; - vec2 texsize; - vec2 pixel_coord_upper; - vec2 pixel_coord_lower; - float height_factor; - float tile_ratio; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillExtrusionTilePropsUBO { - vec4 pattern_from; - vec4 pattern_to; -} tile; - -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { - vec4 color; - vec4 light_color_pad; - vec4 light_position_base; - float height; - float light_intensity; - float vertical_gradient; - float opacity; - float fade; - float from_scale; - float to_scale; - float pad2; -} props; - -layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image0_sampler; - -void main() { - -#if defined(OVERDRAW_INSPECTOR) - out_color = vec4(1.0); - return; -#endif - -#if defined(HAS_UNIFORM_u_pattern_from) - const vec4 pattern_from = tile.pattern_from; -#else - const vec4 pattern_from = frag_pattern_from; -#endif -#if defined(HAS_UNIFORM_u_pattern_to) - const vec4 pattern_to = tile.pattern_to; -#else - const vec4 pattern_to = frag_pattern_to; -#endif - - const vec2 pattern_tl_a = pattern_from.xy; - const vec2 pattern_br_a = pattern_from.zw; - const vec2 pattern_tl_b = pattern_to.xy; - const vec2 pattern_br_b = pattern_to.zw; - - const vec2 imagecoord = mod(frag_pos_a, 1.0); - const vec2 pos = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, imagecoord); - const vec4 color1 = texture(image0_sampler, pos); - - const vec2 imagecoord_b = mod(frag_pos_b, 1.0); - const vec2 pos2 = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, imagecoord_b); - const vec4 color2 = texture(image0_sampler, pos2); - - out_color = mix(color1, color2, props.fade) * frag_lighting; -} -)"; -}; - } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/fill_extrusion.hpp b/include/mbgl/shaders/vulkan/fill_extrusion.hpp new file mode 100644 index 00000000000..9e43a5f87e2 --- /dev/null +++ b/include/mbgl/shaders/vulkan/fill_extrusion.hpp @@ -0,0 +1,391 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace shaders { + +template <> +struct ShaderSource { + static constexpr const char* name = "FillExtrusionShader"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto vertex = R"( + +layout(location = 0) in ivec2 in_position; +layout(location = 1) in ivec4 in_normal_ed; + +#if !defined(HAS_UNIFORM_u_color) +layout(location = 2) in vec4 in_color; +#endif + +#if !defined(HAS_UNIFORM_u_base) +layout(location = 3) in vec2 in_base; +#endif + +#if !defined(HAS_UNIFORM_u_height) +layout(location = 4) in vec2 in_height; +#endif + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableUBO { + mat4 matrix; + vec2 pixel_coord_upper; + vec2 pixel_coord_lower; + float height_factor; + float tile_ratio; + // Interpolations + float base_t; + float height_t; + float color_t; + float pattern_from_t; + float pattern_to_t; + float pad1; +} drawable; + +layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { + vec4 color; + vec4 light_color_pad; + vec4 light_position_base; + float height; + float light_intensity; + float vertical_gradient; + float opacity; + float fade; + float from_scale; + float to_scale; + float pad2; +} props; + +layout(location = 0) out mediump vec4 frag_color; + +void main() { + +#if defined(HAS_UNIFORM_u_base) + const float base = props.light_position_base.w; +#else + const float base = max(unpack_mix_float(in_base, drawable.base_t), 0.0); +#endif + +#if defined(HAS_UNIFORM_u_height) + const float height = props.height; +#else + const float height = max(unpack_mix_float(in_height, drawable.height_t), 0.0); +#endif + +#if defined(HAS_UNIFORM_u_color) + vec4 color = props.color; +#else + vec4 color = unpack_mix_color(in_color, drawable.color_t); +#endif + + const vec3 normal = in_normal_ed.xyz; + const float t = mod(normal.x, 2.0); + const float z = t != 0.0 ? height : base; + + gl_Position = drawable.matrix * vec4(in_position, z, 1.0); + applySurfaceTransform(); + +#if defined(OVERDRAW_INSPECTOR) + frag_color = vec4(1.0); + return; +#endif + + // Relative luminance (how dark/bright is the surface color?) + const float luminance = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722; + + vec4 vcolor = vec4(0.0, 0.0, 0.0, 1.0); + + // Add slight ambient lighting so no extrusions are totally black + color += vec4(0.03, 0.03, 0.03, 1.0); + + // Calculate cos(theta), where theta is the angle between surface normal and diffuse light ray + const float directionalFraction = clamp(dot(normal / 16384.0, props.light_position_base.xyz), 0.0, 1.0); + + // Adjust directional so that the range of values for highlight/shading is + // narrower with lower light intensity and with lighter/brighter surface colors + const float minDirectional = 1.0 - props.light_intensity; + const float maxDirectional = max(1.0 - luminance + props.light_intensity, 1.0); + float directional = mix(minDirectional, maxDirectional, directionalFraction); + + // Add gradient along z axis of side surfaces + if (normal.y != 0.0) { + // This avoids another branching statement, but multiplies by a constant of 0.84 if no + // vertical gradient, and otherwise calculates the gradient based on base + height + // TODO: If we're optimizing to the level of avoiding branches, we should pre-compute + // the square root when height is a uniform. + const float fMin = mix(0.7, 0.98, 1.0 - props.light_intensity); + const float factor = clamp((t + base) * pow(height / 150.0, 0.5), fMin, 1.0); + directional *= (1.0 - props.vertical_gradient) + (props.vertical_gradient * factor); + } + + // Assign final color based on surface + ambient light color, diffuse light directional, + // and light color with lower bounds adjusted to hue of light so that shading is tinted + // with the complementary (opposite) color to the light color + const vec3 light_color = props.light_color_pad.rgb; + const vec3 minLight = mix(vec3(0.0), vec3(0.3), 1.0 - light_color.rgb); + vcolor += vec4(clamp(color.rgb * directional * light_color.rgb, minLight, vec3(1.0)), 0.0); + + frag_color = vcolor * props.opacity; +} +)"; + + static constexpr auto fragment = R"( + +layout(location = 0) in vec4 frag_color; +layout(location = 0) out vec4 out_color; + +void main() { + out_color = frag_color; +} +)"; +}; + +template <> +struct ShaderSource { + static constexpr const char* name = "FillExtrusionPatternShader"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto vertex = R"( + +layout(location = 0) in ivec2 in_position; +layout(location = 1) in ivec4 in_normal_ed; + +#if !defined(HAS_UNIFORM_u_base) +layout(location = 2) in vec2 in_base; +#endif + +#if !defined(HAS_UNIFORM_u_height) +layout(location = 3) in vec2 in_height; +#endif + +#if !defined(HAS_UNIFORM_u_pattern_from) +layout(location = 4) in uvec4 in_pattern_from; +#endif + +#if !defined(HAS_UNIFORM_u_pattern_to) +layout(location = 5) in uvec4 in_pattern_to; +#endif + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableUBO { + mat4 matrix; + vec2 pixel_coord_upper; + vec2 pixel_coord_lower; + float height_factor; + float tile_ratio; + // Interpolations + float base_t; + float height_t; + float color_t; + float pattern_from_t; + float pattern_to_t; + float pad1; +} drawable; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillExtrusionTilePropsUBO { + vec4 pattern_from; + vec4 pattern_to; + vec2 texsize; + float pad1; + float pad2; +} tileProps; + +layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { + vec4 color; + vec4 light_color_pad; + vec4 light_position_base; + float height; + float light_intensity; + float vertical_gradient; + float opacity; + float fade; + float from_scale; + float to_scale; + float pad2; +} props; + +layout(location = 0) out mediump vec4 frag_lighting; +layout(location = 1) out mediump vec2 frag_pos_a; +layout(location = 2) out mediump vec2 frag_pos_b; + +#if !defined(HAS_UNIFORM_u_pattern_from) +layout(location = 3) out mediump vec4 frag_pattern_from; +#endif + +#if !defined(HAS_UNIFORM_u_pattern_to) +layout(location = 4) out mediump vec4 frag_pattern_to; +#endif + +void main() { + +#if defined(HAS_UNIFORM_u_base) + const float base = props.light_position_base.w; +#else + const float base = max(unpack_mix_float(in_base, drawable.base_t), 0.0); +#endif + +#if defined(HAS_UNIFORM_u_height) + const float height = props.height; +#else + const float height = max(unpack_mix_float(in_height, drawable.height_t), 0.0); +#endif + + const vec3 normal = in_normal_ed.xyz; + const float edgedistance = in_normal_ed.w; + const float t = mod(normal.x, 2.0); + const float z = t != 0.0 ? height : base; + + gl_Position = drawable.matrix * vec4(in_position, z, 1.0); + applySurfaceTransform(); + +#if defined(OVERDRAW_INSPECTOR) + frag_color = vec4(1.0); + return; +#endif + +#if defined(HAS_UNIFORM_u_pattern_from) + const mediump vec4 pattern_from = tileProps.pattern_from; +#else + const mediump vec4 pattern_from = in_pattern_from; + frag_pattern_from = in_pattern_from; +#endif + +#if defined(HAS_UNIFORM_u_pattern_to) + const mediump vec4 pattern_to = tileProps.pattern_to; +#else + const mediump vec4 pattern_to = in_pattern_to; + frag_pattern_to = in_pattern_to; +#endif + + const vec2 pattern_tl_a = pattern_from.xy; + const vec2 pattern_br_a = pattern_from.zw; + const vec2 pattern_tl_b = pattern_to.xy; + const vec2 pattern_br_b = pattern_to.zw; + + const float pixelRatio = paintParams.pixel_ratio; + const float tileZoomRatio = drawable.tile_ratio; + const float fromScale = props.from_scale; + const float toScale = props.to_scale; + + const vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); + const vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); + + const vec2 pos = normal.x == 1.0 && normal.y == 0.0 && normal.z == 16384.0 + ? vec2(in_position) // extrusion top + : vec2(edgedistance, z * drawable.height_factor); // extrusion side + + vec4 lighting = vec4(0.0, 0.0, 0.0, 1.0); + float directional = clamp(dot(normal / 16383.0, props.light_position_base.xyz), 0.0, 1.0); + directional = mix((1.0 - props.light_intensity), max((0.5 + props.light_intensity), 1.0), directional); + + if (normal.y != 0.0) { + // This avoids another branching statement, but multiplies by a constant of 0.84 if no vertical gradient, + // and otherwise calculates the gradient based on base + height + directional *= ( + (1.0 - props.vertical_gradient) + + (props.vertical_gradient * clamp((t + base) * pow(height / 150.0, 0.5), mix(0.7, 0.98, 1.0 - props.light_intensity), 1.0))); + } + + lighting.rgb += clamp(directional * props.light_color_pad.rgb, mix(vec3(0.0), vec3(0.3), 1.0 - props.light_color_pad.rgb), vec3(1.0)); + lighting *= props.opacity; + + frag_lighting = lighting; + frag_pos_a = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, fromScale * display_size_a, tileZoomRatio, pos); + frag_pos_b = get_pattern_pos(drawable.pixel_coord_upper, drawable.pixel_coord_lower, toScale * display_size_b, tileZoomRatio, pos); + +#if !defined(HAS_UNIFORM_u_pattern_from) + frag_pattern_from = in_pattern_from; +#endif + +#if !defined(HAS_UNIFORM_u_pattern_to) + frag_pattern_to = in_pattern_to; +#endif +} +)"; + + static constexpr auto fragment = R"( + +layout(location = 0) in mediump vec4 frag_lighting; +layout(location = 1) in mediump vec2 frag_pos_a; +layout(location = 2) in mediump vec2 frag_pos_b; + +#if !defined(HAS_UNIFORM_u_pattern_from) +layout(location = 3) in mediump vec4 frag_pattern_from; +#endif + +#if !defined(HAS_UNIFORM_u_pattern_to) +layout(location = 4) in mediump vec4 frag_pattern_to; +#endif + +layout(location = 0) out vec4 out_color; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillExtrusionTilePropsUBO { + vec4 pattern_from; + vec4 pattern_to; + vec2 texsize; + float pad1; + float pad2; +} tileProps; + +layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { + vec4 color; + vec4 light_color_pad; + vec4 light_position_base; + float height; + float light_intensity; + float vertical_gradient; + float opacity; + float fade; + float from_scale; + float to_scale; + float pad2; +} props; + +layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image0_sampler; + +void main() { + +#if defined(OVERDRAW_INSPECTOR) + out_color = vec4(1.0); + return; +#endif + +#if defined(HAS_UNIFORM_u_pattern_from) + const vec4 pattern_from = tileProps.pattern_from; +#else + const vec4 pattern_from = frag_pattern_from; +#endif +#if defined(HAS_UNIFORM_u_pattern_to) + const vec4 pattern_to = tileProps.pattern_to; +#else + const vec4 pattern_to = frag_pattern_to; +#endif + + const vec2 pattern_tl_a = pattern_from.xy; + const vec2 pattern_br_a = pattern_from.zw; + const vec2 pattern_tl_b = pattern_to.xy; + const vec2 pattern_br_b = pattern_to.zw; + + const vec2 imagecoord = mod(frag_pos_a, 1.0); + const vec2 pos = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, imagecoord); + const vec4 color1 = texture(image0_sampler, pos); + + const vec2 imagecoord_b = mod(frag_pos_b, 1.0); + const vec2 pos2 = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, imagecoord_b); + const vec4 color2 = texture(image0_sampler, pos2); + + out_color = mix(color1, color2, props.fade) * frag_lighting; +} +)"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/heatmap.hpp b/include/mbgl/shaders/vulkan/heatmap.hpp index 8d45f7e7241..da11f000092 100644 --- a/include/mbgl/shaders/vulkan/heatmap.hpp +++ b/include/mbgl/shaders/vulkan/heatmap.hpp @@ -10,10 +10,10 @@ template <> struct ShaderSource { static constexpr const char* name = "HeatmapShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -38,15 +38,11 @@ layout(location = 2) in vec2 in_radius; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HeatmapDrawableUBO { mat4 matrix; float extrude_scale; - float pad1; - vec2 pad2; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform HeatmapInterpolateUBO { + // Interpolations float weight_t; float radius_t; - vec2 pad1; -} interp; + float pad1; +} drawable; layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapEvaluatedPropsUBO { float weight; @@ -63,13 +59,13 @@ void main() { #if defined(HAS_UNIFORM_u_weight) const float weight = props.weight; #else - const float weight = unpack_mix_float(in_weight, interp.weight_t); + const float weight = unpack_mix_float(in_weight, drawable.weight_t); #endif #if defined(HAS_UNIFORM_u_radius) const float radius = props.radius; #else - const float radius = unpack_mix_float(in_radius, interp.radius_t); + const float radius = unpack_mix_float(in_radius, drawable.radius_t); #endif // unencode the extrusion vector that we snuck into the a_pos vector @@ -138,63 +134,5 @@ void main() { )"; }; -template <> -struct ShaderSource { - static constexpr const char* name = "HeatmapTextureShader"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto vertex = R"( - -layout(location = 0) in ivec2 in_position; - -layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapTexturePropsUBO { - mat4 matrix; - float opacity; - float pad1, pad2, pad3; -} props; - -layout(location = 0) out vec2 frag_position; - -void main() { - - gl_Position = props.matrix * vec4(in_position * global.world_size, 0, 1); - applySurfaceTransform(); - - frag_position = in_position; -} -)"; - - static constexpr auto fragment = R"( - -layout(location = 0) in vec2 frag_position; -layout(location = 0) out vec4 out_color; - -layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapTexturePropsUBO { - mat4 matrix; - float opacity; - float pad1, pad2, pad3; -} props; - -layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; -layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 1) uniform sampler2D color_ramp_sampler; - -void main() { - -#if defined(OVERDRAW_INSPECTOR) - out_color = vec4(1.0); - return; -#endif - - const float t = texture(image_sampler, frag_position).r; - const vec4 color = texture(color_ramp_sampler, vec2(t, 0.5)); - out_color = color * props.opacity; -} -)"; -}; - } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/heatmap_texture.hpp b/include/mbgl/shaders/vulkan/heatmap_texture.hpp new file mode 100644 index 00000000000..59dae6baf92 --- /dev/null +++ b/include/mbgl/shaders/vulkan/heatmap_texture.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace shaders { + +template <> +struct ShaderSource { + static constexpr const char* name = "HeatmapTextureShader"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto vertex = R"( + +layout(location = 0) in ivec2 in_position; + +layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapTexturePropsUBO { + mat4 matrix; + float opacity; + float pad1; + float pad2; + float pad3; +} props; + +layout(location = 0) out vec2 frag_position; + +void main() { + + gl_Position = props.matrix * vec4(in_position * paintParams.world_size, 0, 1); + applySurfaceTransform(); + + frag_position = in_position; +} +)"; + + static constexpr auto fragment = R"( + +layout(location = 0) in vec2 frag_position; +layout(location = 0) out vec4 out_color; + +layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapTexturePropsUBO { + mat4 matrix; + float opacity; + float pad1; + float pad2; + float pad3; +} props; + +layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; +layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 1) uniform sampler2D color_ramp_sampler; + +void main() { + +#if defined(OVERDRAW_INSPECTOR) + out_color = vec4(1.0); + return; +#endif + + const float t = texture(image_sampler, frag_position).r; + const vec4 color = texture(color_ramp_sampler, vec2(t, 0.5)); + out_color = color * props.opacity; +} +)"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/hillshade.hpp b/include/mbgl/shaders/vulkan/hillshade.hpp index f034a07e5fe..ca1fe8da105 100644 --- a/include/mbgl/shaders/vulkan/hillshade.hpp +++ b/include/mbgl/shaders/vulkan/hillshade.hpp @@ -6,129 +6,11 @@ namespace mbgl { namespace shaders { -template <> -struct ShaderSource { - static constexpr const char* name = "HillshadePrepareShader"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto vertex = R"( - -layout(location = 0) in ivec2 in_position; -layout(location = 1) in ivec2 in_texture_position; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HillshadePrepareDrawableUBO { - mat4 matrix; - vec4 unpack; - vec2 dimension; - float zoom; - float maxzoom; -} drawable; - -layout(location = 0) out vec2 frag_position; - -void main() { - - gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0); - applySurfaceTransform(); - - const vec2 epsilon = vec2(1.0) / drawable.dimension; - const float scale = (drawable.dimension.x - 2.0) / drawable.dimension.x; - frag_position = in_texture_position / 8192.0 * scale + epsilon; -} -)"; - - static constexpr auto fragment = R"( - -layout(location = 0) in vec2 frag_position; -layout(location = 0) out vec4 out_color; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HillshadePrepareDrawableUBO { - mat4 matrix; - vec4 unpack; - vec2 dimension; - float zoom; - float maxzoom; -} drawable; - -layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; - -float getElevation(vec2 coord, float bias, sampler2D image_sampler, vec4 unpack) { - // Convert encoded elevation value to meters - vec4 data = texture(image_sampler, coord) * 255.0; - data.a = -1.0; - return dot(data, unpack) / 4.0; -} - -void main() { - -#if defined(OVERDRAW_INSPECTOR) - out_color = vec4(1.0); - return; -#endif - - const vec2 epsilon = 1.0 / drawable.dimension; - - // queried pixels: - // +-----------+ - // | | | | - // | a | b | c | - // | | | | - // +-----------+ - // | | | | - // | d | e | f | - // | | | | - // +-----------+ - // | | | | - // | g | h | i | - // | | | | - // +-----------+ - - float a = getElevation(frag_position + vec2(-epsilon.x, -epsilon.y), 0.0, image_sampler, drawable.unpack); - float b = getElevation(frag_position + vec2(0, -epsilon.y), 0.0, image_sampler, drawable.unpack); - float c = getElevation(frag_position + vec2(epsilon.x, -epsilon.y), 0.0, image_sampler, drawable.unpack); - float d = getElevation(frag_position + vec2(-epsilon.x, 0), 0.0, image_sampler, drawable.unpack); - //float e = getElevation(frag_position, 0.0, image_sampler, drawable.unpack); - float f = getElevation(frag_position + vec2(epsilon.x, 0), 0.0, image_sampler, drawable.unpack); - float g = getElevation(frag_position + vec2(-epsilon.x, epsilon.y), 0.0, image_sampler, drawable.unpack); - float h = getElevation(frag_position + vec2(0, epsilon.y), 0.0, image_sampler, drawable.unpack); - float i = getElevation(frag_position + vec2(epsilon.x, epsilon.y), 0.0, image_sampler, drawable.unpack); - - // here we divide the x and y slopes by 8 * pixel size - // where pixel size (aka meters/pixel) is: - // circumference of the world / (pixels per tile * number of tiles) - // which is equivalent to: 8 * 40075016.6855785 / (512 * pow(2, u_zoom)) - // which can be reduced to: pow(2, 19.25619978527 - u_zoom) - // we want to vertically exaggerate the hillshading though, because otherwise - // it is barely noticeable at low zooms. to do this, we multiply this by some - // scale factor pow(2, (u_zoom - u_maxzoom) * a) where a is an arbitrary value - // Here we use a=0.3 which works out to the expression below. see - // nickidlugash's awesome breakdown for more info - // https://github.com/mapbox/mapbox-gl-js/pull/5286#discussion_r148419556 - float exaggeration = drawable.zoom < 2.0 ? 0.4 : drawable.zoom < 4.5 ? 0.35 : 0.3; - - vec2 deriv = vec2( - (c + f + f + i) - (a + d + d + g), - (g + h + h + i) - (a + b + b + c) - ) / pow(2.0, (drawable.zoom - drawable.maxzoom) * exaggeration + 19.2562 - drawable.zoom); - - out_color = clamp(vec4( - deriv.x / 2.0 + 0.5, - deriv.y / 2.0 + 0.5, - 1.0, - 1.0), 0.0, 1.0); -} -)"; -}; - template <> struct ShaderSource { static constexpr const char* name = "HillshadeShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -140,8 +22,6 @@ layout(location = 1) in ivec2 in_texture_position; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HillshadeDrawableUBO { mat4 matrix; - vec2 latrange; - vec2 light; } drawable; layout(location = 0) out vec2 frag_position; @@ -161,11 +41,10 @@ void main() { layout(location = 0) in vec2 frag_position; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HillshadeDrawableUBO { - mat4 matrix; +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform HillshadeTilePropsUBO { vec2 latrange; vec2 light; -} drawable; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform HillshadeEvaluatedPropsUBO { vec4 highlight; @@ -188,16 +67,16 @@ void main() { // We divide the slope by a scale factor based on the cosin of the pixel's approximate latitude // to account for mercator projection distortion. see #4807 for details - float scaleFactor = cos(radians((drawable.latrange[0] - drawable.latrange[1]) * frag_position.y + drawable.latrange[1])); + float scaleFactor = cos(radians((tileProps.latrange[0] - tileProps.latrange[1]) * frag_position.y + tileProps.latrange[1])); // We also multiply the slope by an arbitrary z-factor of 1.25 float slope = atan(1.25 * length(deriv) / scaleFactor); float aspect = deriv.x != 0.0 ? atan(deriv.y, -deriv.x) : M_PI / 2.0 * (deriv.y > 0.0 ? 1.0 : -1.0); - float intensity = drawable.light.x; + float intensity = tileProps.light.x; // We add PI to make this property match the global light object, which adds PI/2 to the light's azimuthal // position property to account for 0deg corresponding to north/the top of the viewport in the style spec // and the original shader was written to accept (-illuminationDirection - 90) as the azimuthal. - float azimuth = drawable.light.y + M_PI; + float azimuth = tileProps.light.y + M_PI; // We scale the slope exponentially based on intensity, using a calculation similar to // the exponential interpolation function in the style spec: diff --git a/include/mbgl/shaders/vulkan/hillshade_prepare.hpp b/include/mbgl/shaders/vulkan/hillshade_prepare.hpp new file mode 100644 index 00000000000..872c48690c2 --- /dev/null +++ b/include/mbgl/shaders/vulkan/hillshade_prepare.hpp @@ -0,0 +1,130 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace shaders { + +template <> +struct ShaderSource { + static constexpr const char* name = "HillshadePrepareShader"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto vertex = R"( + +layout(location = 0) in ivec2 in_position; +layout(location = 1) in ivec2 in_texture_position; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HillshadePrepareDrawableUBO { + mat4 matrix; +} drawable; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform HillshadePrepareTilePropsUBO { + vec4 unpack; + vec2 dimension; + float zoom; + float maxzoom; +} tileProps; + +layout(location = 0) out vec2 frag_position; + +void main() { + + gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0); + applySurfaceTransform(); + + const vec2 epsilon = vec2(1.0) / tileProps.dimension; + const float scale = (tileProps.dimension.x - 2.0) / tileProps.dimension.x; + frag_position = in_texture_position / 8192.0 * scale + epsilon; +} +)"; + + static constexpr auto fragment = R"( + +layout(location = 0) in vec2 frag_position; +layout(location = 0) out vec4 out_color; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform HillshadePrepareTilePropsUBO { + vec4 unpack; + vec2 dimension; + float zoom; + float maxzoom; +} tileProps; + +layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; + +float getElevation(vec2 coord, float bias, sampler2D image_sampler, vec4 unpack) { + // Convert encoded elevation value to meters + vec4 data = texture(image_sampler, coord) * 255.0; + data.a = -1.0; + return dot(data, unpack) / 4.0; +} + +void main() { + +#if defined(OVERDRAW_INSPECTOR) + out_color = vec4(1.0); + return; +#endif + + const vec2 epsilon = 1.0 / tileProps.dimension; + + // queried pixels: + // +-----------+ + // | | | | + // | a | b | c | + // | | | | + // +-----------+ + // | | | | + // | d | e | f | + // | | | | + // +-----------+ + // | | | | + // | g | h | i | + // | | | | + // +-----------+ + + float a = getElevation(frag_position + vec2(-epsilon.x, -epsilon.y), 0.0, image_sampler, tileProps.unpack); + float b = getElevation(frag_position + vec2(0, -epsilon.y), 0.0, image_sampler, tileProps.unpack); + float c = getElevation(frag_position + vec2(epsilon.x, -epsilon.y), 0.0, image_sampler, tileProps.unpack); + float d = getElevation(frag_position + vec2(-epsilon.x, 0), 0.0, image_sampler, tileProps.unpack); + //float e = getElevation(frag_position, 0.0, image_sampler, tileProps.unpack); + float f = getElevation(frag_position + vec2(epsilon.x, 0), 0.0, image_sampler, tileProps.unpack); + float g = getElevation(frag_position + vec2(-epsilon.x, epsilon.y), 0.0, image_sampler, tileProps.unpack); + float h = getElevation(frag_position + vec2(0, epsilon.y), 0.0, image_sampler, tileProps.unpack); + float i = getElevation(frag_position + vec2(epsilon.x, epsilon.y), 0.0, image_sampler, tileProps.unpack); + + // here we divide the x and y slopes by 8 * pixel size + // where pixel size (aka meters/pixel) is: + // circumference of the world / (pixels per tile * number of tiles) + // which is equivalent to: 8 * 40075016.6855785 / (512 * pow(2, u_zoom)) + // which can be reduced to: pow(2, 19.25619978527 - u_zoom) + // we want to vertically exaggerate the hillshading though, because otherwise + // it is barely noticeable at low zooms. to do this, we multiply this by some + // scale factor pow(2, (u_zoom - u_maxzoom) * a) where a is an arbitrary value + // Here we use a=0.3 which works out to the expression below. see + // nickidlugash's awesome breakdown for more info + // https://github.com/mapbox/mapbox-gl-js/pull/5286#discussion_r148419556 + float exaggeration = tileProps.zoom < 2.0 ? 0.4 : tileProps.zoom < 4.5 ? 0.35 : 0.3; + + vec2 deriv = vec2( + (c + f + f + i) - (a + d + d + g), + (g + h + h + i) - (a + b + b + c) + ) / pow(2.0, (tileProps.zoom - tileProps.maxzoom) * exaggeration + 19.2562 - tileProps.zoom); + + out_color = clamp(vec4( + deriv.x / 2.0 + 0.5, + deriv.y / 2.0 + 0.5, + 1.0, + 1.0), 0.0, 1.0); +} +)"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/line.hpp b/include/mbgl/shaders/vulkan/line.hpp index 08716d654c0..6dddd3fb9c6 100644 --- a/include/mbgl/shaders/vulkan/line.hpp +++ b/include/mbgl/shaders/vulkan/line.hpp @@ -10,10 +10,10 @@ template <> struct ShaderSource { static constexpr const char* name = "LineShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( @@ -47,18 +47,15 @@ layout(location = 7) in vec2 in_width; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineDrawableUBO { mat4 matrix; mediump float ratio; - float pad1, pad2, pad3; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineInterpolationUBO { + // Interpolations float color_t; float blur_t; float opacity_t; float gapwidth_t; float offset_t; float width_t; - float pad1, pad2; -} interp; + float pad1; +} drawable; layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { vec4 color; @@ -91,31 +88,31 @@ layout(location = 5) out lowp float frag_opacity; void main() { #ifndef HAS_UNIFORM_u_color - frag_color = unpack_mix_color(in_color, interp.color_t); + frag_color = unpack_mix_color(in_color, drawable.color_t); #endif #ifndef HAS_UNIFORM_u_blur - frag_blur = unpack_mix_float(in_blur, interp.blur_t); + frag_blur = unpack_mix_float(in_blur, drawable.blur_t); #endif #ifndef HAS_UNIFORM_u_opacity - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif #ifndef HAS_UNIFORM_u_gapwidth - const mediump float gapwidth = unpack_mix_float(in_gapwidth, interp.gapwidth_t) / 2.0; + const mediump float gapwidth = unpack_mix_float(in_gapwidth, drawable.gapwidth_t) / 2.0; #else const mediump float gapwidth = props.gapwidth / 2.0; #endif #ifndef HAS_UNIFORM_u_offset - const lowp float offset = unpack_mix_float(in_offset, interp.offset_t) * -1.0; + const lowp float offset = unpack_mix_float(in_offset, drawable.offset_t) * -1.0; #else const lowp float offset = props.offset * -1.0; #endif #ifndef HAS_UNIFORM_u_width - mediump float width = unpack_mix_float(in_width, interp.width_t); + mediump float width = unpack_mix_float(in_width, drawable.width_t); #else mediump float width = props.width; #endif @@ -159,7 +156,7 @@ void main() { // calculate how much the perspective view squishes or stretches the extrude float extrude_length_without_perspective = length(dist); - float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * global.units_to_pixels); + float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * paintParams.units_to_pixels); frag_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective; frag_width2 = vec2(outset, inset); @@ -241,7 +238,7 @@ template <> struct ShaderSource { static constexpr const char* name = "LineGradientShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -271,21 +268,18 @@ layout(location = 5) in vec2 in_offset; layout(location = 6) in vec2 in_width; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineGradientDrawableUBO { mat4 matrix; mediump float ratio; - float pad1, pad2, pad3; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineInterpolationUBO { - float color_t; + // Interpolations float blur_t; float opacity_t; float gapwidth_t; float offset_t; float width_t; - float pad1, pad2; -} interp; + float pad1; + float pad2; +} drawable; layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { vec4 color; @@ -315,27 +309,27 @@ layout(location = 5) out lowp float frag_opacity; void main() { #ifndef HAS_UNIFORM_u_blur - frag_blur = unpack_mix_float(in_blur, interp.blur_t); + frag_blur = unpack_mix_float(in_blur, drawable.blur_t); #endif #ifndef HAS_UNIFORM_u_opacity - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif #ifndef HAS_UNIFORM_u_gapwidth - mediump float gapwidth = unpack_mix_float(in_gapwidth, interp.gapwidth_t) / 2.0; + mediump float gapwidth = unpack_mix_float(in_gapwidth, drawable.gapwidth_t) / 2.0; #else mediump float gapwidth = props.gapwidth / 2.0; #endif #ifndef HAS_UNIFORM_u_offset - const lowp float offset = unpack_mix_float(in_offset, interp.offset_t) * -1.0; + const lowp float offset = unpack_mix_float(in_offset, drawable.offset_t) * -1.0; #else const lowp float offset = props.offset * -1.0; #endif #ifndef HAS_UNIFORM_u_width - mediump float width = unpack_mix_float(in_width, interp.width_t); + mediump float width = unpack_mix_float(in_width, drawable.width_t); #else mediump float width = props.width; #endif @@ -380,7 +374,7 @@ void main() { // calculate how much the perspective view squishes or stretches the extrude float extrude_length_without_perspective = length(dist); - float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * global.units_to_pixels); + float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * paintParams.units_to_pixels); frag_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective; frag_width2 = vec2(outset, inset); @@ -459,7 +453,7 @@ template <> struct ShaderSource { static constexpr const char* name = "LinePatternShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -497,15 +491,10 @@ layout(location = 7) in uvec4 in_pattern_from; layout(location = 8) in uvec4 in_pattern_to; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LinePatternDrawableUBO { mat4 matrix; - vec4 scale; - vec2 texsize; float ratio; - float fade; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineInterpolationUBO { + // Interpolations float blur_t; float opacity_t; float offset_t; @@ -513,13 +502,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineInterpolationUBO { float width_t; float pattern_from_t; float pattern_to_t; - float pad1; -} interp; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform LinePatternTilePropertiesUBO { - vec4 pattern_from; - vec4 pattern_to; -} tile; +} drawable; layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { vec4 color; @@ -557,27 +540,27 @@ layout(location = 7) out mediump vec4 frag_pattern_to; void main() { #ifndef HAS_UNIFORM_u_blur - frag_blur = unpack_mix_float(in_blur, interp.blur_t); + frag_blur = unpack_mix_float(in_blur, drawable.blur_t); #endif #ifndef HAS_UNIFORM_u_opacity - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif #ifndef HAS_UNIFORM_u_gapwidth - const mediump float gapwidth = unpack_mix_float(in_gapwidth, interp.gapwidth_t) / 2.0; + const mediump float gapwidth = unpack_mix_float(in_gapwidth, drawable.gapwidth_t) / 2.0; #else const mediump float gapwidth = props.gapwidth / 2.0; #endif #ifndef HAS_UNIFORM_u_offset - const lowp float offset = unpack_mix_float(in_offset, interp.offset_t) * -1.0; + const lowp float offset = unpack_mix_float(in_offset, drawable.offset_t) * -1.0; #else const lowp float offset = props.offset * -1.0; #endif #ifndef HAS_UNIFORM_u_width - mediump float width = unpack_mix_float(in_width, interp.width_t); + mediump float width = unpack_mix_float(in_width, drawable.width_t); #else mediump float width = props.width; #endif @@ -630,7 +613,7 @@ void main() { // calculate how much the perspective view squishes or stretches the extrude float extrude_length_without_perspective = length(dist); - float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * global.units_to_pixels); + float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * paintParams.units_to_pixels); frag_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective; frag_width2 = vec2(outset, inset); @@ -663,18 +646,14 @@ layout(location = 7) in mediump vec4 frag_pattern_to; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineDrawableUBO { - mat4 matrix; +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LinePatternTilePropertiesUBO { + vec4 pattern_from; + vec4 pattern_to; vec4 scale; vec2 texsize; - float ratio; float fade; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform LinePatternTilePropertiesUBO { - vec4 pattern_from; - vec4 pattern_to; -} tile; + float pad1; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { vec4 color; @@ -710,13 +689,13 @@ void main() { #endif #ifdef HAS_UNIFORM_u_pattern_from - const lowp vec4 pattern_from = tile.pattern_from; + const lowp vec4 pattern_from = tileProps.pattern_from; #else const lowp vec4 pattern_from = frag_pattern_from; #endif #ifdef HAS_UNIFORM_u_pattern_to - const lowp vec4 pattern_to = tile.pattern_to; + const lowp vec4 pattern_to = tileProps.pattern_to; #else const lowp vec4 pattern_to = frag_pattern_to; #endif @@ -726,10 +705,10 @@ void main() { const vec2 pattern_tl_b = pattern_to.xy; const vec2 pattern_br_b = pattern_to.zw; - const float pixelRatio = drawable.scale.x; - const float tileZoomRatio = drawable.scale.y; - const float fromScale = drawable.scale.z; - const float toScale = drawable.scale.w; + const float pixelRatio = tileProps.scale.x; + const float tileZoomRatio = tileProps.scale.y; + const float fromScale = tileProps.scale.z; + const float toScale = tileProps.scale.w; const vec2 display_size_a = vec2((pattern_br_a.x - pattern_tl_a.x) / pixelRatio, (pattern_br_a.y - pattern_tl_a.y) / pixelRatio); const vec2 display_size_b = vec2((pattern_br_b.x - pattern_tl_b.x) / pixelRatio, (pattern_br_b.y - pattern_tl_b.y) / pixelRatio); @@ -756,10 +735,10 @@ void main() { // the texture coordinate const float y_a = 0.5 + (frag_normal.y * clamp(frag_width2.x, 0.0, (pattern_size_a.y + 2.0) / 2.0) / pattern_size_a.y); const float y_b = 0.5 + (frag_normal.y * clamp(frag_width2.x, 0.0, (pattern_size_b.y + 2.0) / 2.0) / pattern_size_b.y); - const vec2 pos_a = mix(pattern_tl_a / drawable.texsize, pattern_br_a / drawable.texsize, vec2(x_a, y_a)); - const vec2 pos_b = mix(pattern_tl_b / drawable.texsize, pattern_br_b / drawable.texsize, vec2(x_b, y_b)); + const vec2 pos_a = mix(pattern_tl_a / tileProps.texsize, pattern_br_a / tileProps.texsize, vec2(x_a, y_a)); + const vec2 pos_b = mix(pattern_tl_b / tileProps.texsize, pattern_br_b / tileProps.texsize, vec2(x_b, y_b)); - const vec4 color = mix(texture(image0_sampler, pos_a), texture(image0_sampler, pos_b), drawable.fade); + const vec4 color = mix(texture(image0_sampler, pos_a), texture(image0_sampler, pos_b), tileProps.fade); out_color = color * (alpha * opacity); } @@ -812,15 +791,10 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineSDFDrawableUBO { mat4 matrix; vec2 patternscale_a; vec2 patternscale_b; - float ratio; float tex_y_a; float tex_y_b; - float sdfgamma; - float mix; - float pad1, pad2, pad3; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineSDFInterpolationUBO { + float ratio; + // Interpolations float color_t; float blur_t; float opacity_t; @@ -829,7 +803,8 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineSDFInterpolationUB float width_t; float floorwidth_t; float pad1; -} interp; + float pad2; +} drawable; layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { vec4 color; @@ -868,38 +843,38 @@ layout(location = 8) out mediump float frag_floorwidth; void main() { #ifndef HAS_UNIFORM_u_color - frag_color = unpack_mix_color(in_color, interp.color_t); + frag_color = unpack_mix_color(in_color, intdrawableerp.color_t); #endif #ifndef HAS_UNIFORM_u_blur - frag_blur = unpack_mix_float(in_blur, interp.blur_t); + frag_blur = unpack_mix_float(in_blur, drawable.blur_t); #endif #ifndef HAS_UNIFORM_u_opacity - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif #ifndef HAS_UNIFORM_u_floorwidth - const float floorwidth = unpack_mix_float(in_floorwidth, interp.floorwidth_t); + const float floorwidth = unpack_mix_float(in_floorwidth, drawable.floorwidth_t); frag_floorwidth = floorwidth; #else const float floorwidth = props.floorwidth; #endif #ifndef HAS_UNIFORM_u_offset - const mediump float offset = unpack_mix_float(in_offset, interp.offset_t) * -1.0; + const mediump float offset = unpack_mix_float(in_offset, drawable.offset_t) * -1.0; #else const mediump float offset = props.offset * -1.0; #endif #ifndef HAS_UNIFORM_u_width - const mediump float width = unpack_mix_float(in_width, interp.width_t); + const mediump float width = unpack_mix_float(in_width, drawable.width_t); #else const mediump float width = props.width; #endif #ifndef HAS_UNIFORM_u_gapwidth - const mediump float gapwidth = unpack_mix_float(in_gapwidth, interp.gapwidth_t) / 2.0; + const mediump float gapwidth = unpack_mix_float(in_gapwidth, drawable.gapwidth_t) / 2.0; #else const mediump float gapwidth = props.gapwidth / 2.0; #endif @@ -945,7 +920,7 @@ void main() { // calculate how much the perspective view squishes or stretches the extrude float extrude_length_without_perspective = length(dist); - float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * global.units_to_pixels); + float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * paintParams.units_to_pixels); frag_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective; frag_width2 = vec2(outset, inset); @@ -981,28 +956,12 @@ layout(location = 8) in mediump float frag_floorwidth; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineSDFDrawableUBO { - mat4 matrix; - vec2 patternscale_a; - vec2 patternscale_b; - float ratio; - float tex_y_a; - float tex_y_b; +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineSDFInterpolationUBO { float sdfgamma; float mix; - float pad1, pad2, pad3; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineSDFInterpolationUBO { - float color_t; - float blur_t; - float opacity_t; - float gapwidth_t; - float offset_t; - float width_t; - float floorwidth_t; float pad1; -} interp; + float pad2; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { vec4 color; @@ -1058,9 +1017,9 @@ void main() { const float sdfdist_a = texture(image0_sampler, frag_tex_a).a; const float sdfdist_b = texture(image0_sampler, frag_tex_b).a; - const float sdfdist = mix(sdfdist_a, sdfdist_b, drawable.mix); + const float sdfdist = mix(sdfdist_a, sdfdist_b, tileProps.mix); const float alpha = clamp(min(dist - (frag_width2.y - blur2), frag_width2.x - dist) / blur2, 0.0, 1.0) * - smoothstep(0.5 - drawable.sdfgamma / floorwidth, 0.5 + drawable.sdfgamma / floorwidth, sdfdist); + smoothstep(0.5 - tileProps.sdfgamma / floorwidth, 0.5 + tileProps.sdfgamma / floorwidth, sdfdist); out_color = color * (alpha * opacity); } diff --git a/include/mbgl/shaders/vulkan/location_indicator.hpp b/include/mbgl/shaders/vulkan/location_indicator.hpp new file mode 100644 index 00000000000..f677bb29670 --- /dev/null +++ b/include/mbgl/shaders/vulkan/location_indicator.hpp @@ -0,0 +1,87 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace shaders { + +template <> +struct ShaderSource { + static constexpr const char* name = "LocationIndicatorShader"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto vertex = R"( +layout(location = 0) in vec2 in_position; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LocationIndicatorDrawableUBO { + mat4 matrix; + vec4 color; +} drawable; + +void main() { + gl_Position = drawable.matrix * vec4(in_position, 0, 1); + applySurfaceTransform(); +} +)"; + + static constexpr auto fragment = R"( +layout(location = 0) out vec4 out_color; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LocationIndicatorDrawableUBO { + mat4 matrix; + vec4 color; +} drawable; + +void main() { + out_color = drawable.color; +} +)"; +}; + +template <> +struct ShaderSource { + static constexpr const char* name = "LocationIndicatorTexturedShader"; + + static const std::array uniforms; + static const std::array attributes; + static constexpr std::array instanceAttributes{}; + static const std::array textures; + + static constexpr auto vertex = R"( +layout(location = 0) in vec2 in_position; +layout(location = 1) in vec2 in_texcoord; + +layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LocationIndicatorDrawableUBO { + mat4 matrix; + vec4 color; +} drawable; + +layout(location = 0) out vec2 frag_uv; + +void main() { + gl_Position = drawable.matrix * vec4(in_position, 0, 1); + applySurfaceTransform(); + + frag_uv = in_texcoord; +} +)"; + + static constexpr auto fragment = R"( +layout(location = 0) in vec2 frag_uv; +layout(location = 0) out vec4 out_color; + +layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; + +void main() { + out_color = texture(image_sampler, frag_uv); +} +)"; +}; + +} // namespace shaders +} // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/raster.hpp b/include/mbgl/shaders/vulkan/raster.hpp index c8677d6d488..c4542df2d06 100644 --- a/include/mbgl/shaders/vulkan/raster.hpp +++ b/include/mbgl/shaders/vulkan/raster.hpp @@ -35,7 +35,8 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform RasterEvaluatedPropsUBO { float brightness_high; float saturation_factor; float contrast_factor; - float pad1, pad2; + float pad1; + float pad2; } props; layout(location = 0) out vec2 frag_position0; @@ -74,7 +75,8 @@ layout(set = LAYER_SET_INDEX, binding = 0) uniform RasterEvaluatedPropsUBO { float brightness_high; float saturation_factor; float contrast_factor; - float pad1, pad2; + float pad1; + float pad2; } props; layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image0_sampler; diff --git a/include/mbgl/shaders/vulkan/symbol.hpp b/include/mbgl/shaders/vulkan/symbol.hpp index 67511b5a2f4..7ede918ea23 100644 --- a/include/mbgl/shaders/vulkan/symbol.hpp +++ b/include/mbgl/shaders/vulkan/symbol.hpp @@ -10,7 +10,7 @@ template <> struct ShaderSource { static constexpr const char* name = "SymbolIconShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -31,32 +31,27 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; + vec2 texsize; vec2 texsize_icon; - float gamma_scale; - bool rotate_symbol; - vec2 pad; -} drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { - bool is_text; - bool is_halo; + bool is_text_prop; + bool rotate_symbol; bool pitch_with_map; bool is_size_zoom_constant; bool is_size_feature_constant; + float size_t; float size; - float padding; -} tile; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform SymbolInterpolateUBO { + // Interpolations float fill_color_t; float halo_color_t; float opacity_t; float halo_width_t; float halo_blur_t; - float pad1, pad2, pad3; -} interp; + float pad1; +} drawable; layout(location = 0) out mediump vec2 frag_tex; layout(location = 1) out mediump float frag_opacity; @@ -76,20 +71,20 @@ void main() { const float segment_angle = -in_projected_pos[2]; float size; - if (!tile.is_size_zoom_constant && !tile.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], tile.size_t) / 128.0; - } else if (tile.is_size_zoom_constant && !tile.is_size_feature_constant) { + if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0; + } else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { size = a_size_min / 128.0; } else { - size = tile.size; + size = drawable.size; } const vec4 projectedPoint = drawable.matrix * vec4(a_pos, 0, 1); const float camera_to_anchor_distance = projectedPoint.w; // See comments in symbol_sdf.vertex - const float distance_ratio = tile.pitch_with_map ? - camera_to_anchor_distance / global.camera_to_center_distance : - global.camera_to_center_distance / camera_to_anchor_distance; + const float distance_ratio = drawable.pitch_with_map ? + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.camera_to_center_distance / camera_to_anchor_distance; const float perspective_ratio = clamp( 0.5 + 0.5 * distance_ratio, 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles @@ -97,7 +92,7 @@ void main() { size *= perspective_ratio; - const float fontScale = tile.is_text ? size / 24.0 : size; + const float fontScale = drawable.is_text_prop ? size / 24.0 : size; float symbol_rotation = 0.0; if (drawable.rotate_symbol) { @@ -106,7 +101,7 @@ void main() { const vec2 a = projectedPoint.xy / projectedPoint.w; const vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; - symbol_rotation = atan((b.y - a.y) / global.aspect_ratio, b.x - a.x); + symbol_rotation = atan((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); } const float angle_sin = sin(segment_angle + symbol_rotation); @@ -120,7 +115,7 @@ void main() { applySurfaceTransform(); const vec2 raw_fade_opacity = unpack_opacity(in_fade_opacity); - const float fade_change = raw_fade_opacity[1] > 0.5 ? global.symbol_fade_change : -global.symbol_fade_change; + const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; const float fade_opacity = max(0.0, min(1.0, raw_fade_opacity[0] + fade_change)); frag_tex = a_tex / drawable.texsize; @@ -128,7 +123,7 @@ void main() { #if defined(HAS_UNIFORM_u_opacity) frag_opacity = fade_opacity; #else - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t) * fade_opacity; + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t) * fade_opacity; #endif } )"; @@ -143,13 +138,9 @@ layout(location = 0) out vec4 out_color; layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { bool is_text; bool is_halo; - bool pitch_with_map; - bool is_size_zoom_constant; - bool is_size_feature_constant; - float size_t; - float size; - float padding; -} tile; + float gamma_scale; + float pad1; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; @@ -175,7 +166,7 @@ void main() { #endif #if defined(HAS_UNIFORM_u_opacity) - const float opacity = (tile.is_text ? props.text_opacity : props.icon_opacity) * frag_opacity; + const float opacity = (tileProps.is_text ? props.text_opacity : props.icon_opacity) * frag_opacity; #else const float opacity = frag_opacity; // fade_opacity is baked in for this case #endif @@ -189,7 +180,7 @@ template <> struct ShaderSource { static constexpr const char* name = "SymbolSDFIconShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -226,32 +217,27 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; + vec2 texsize; vec2 texsize_icon; - float gamma_scale; - bool rotate_symbol; - vec2 pad; -} drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { - bool is_text; - bool is_halo; + bool is_text_prop; + bool rotate_symbol; bool pitch_with_map; bool is_size_zoom_constant; bool is_size_feature_constant; + float size_t; float size; - float padding; -} tile; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform SymbolInterpolateUBO { + // Interpolations float fill_color_t; float halo_color_t; float opacity_t; float halo_width_t; float halo_blur_t; - float pad1, pad2, pad3; -} interp; + float pad1; +} drawable; layout(location = 0) out mediump vec2 frag_tex; layout(location = 1) out mediump float frag_fade_opacity; @@ -291,12 +277,12 @@ void main() { const float segment_angle = -in_projected_pos[2]; float size; - if (!tile.is_size_zoom_constant && !tile.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], tile.size_t) / 128.0; - } else if (tile.is_size_zoom_constant && !tile.is_size_feature_constant) { + if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0; + } else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { size = a_size_min / 128.0; } else { - size = tile.size; + size = drawable.size; } const vec4 projectedPoint = drawable.matrix * vec4(a_pos, 0, 1); @@ -307,9 +293,9 @@ void main() { // If the label isn't pitched with the map, we do layout in viewport space, // which makes labels in the distance larger relative to the features around // them. We counteract part of that effect by dividing by the perspective ratio. - const float distance_ratio = tile.pitch_with_map ? - camera_to_anchor_distance / global.camera_to_center_distance : - global.camera_to_center_distance / camera_to_anchor_distance; + const float distance_ratio = drawable.pitch_with_map ? + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.camera_to_center_distance / camera_to_anchor_distance; const float perspective_ratio = clamp( 0.5 + 0.5 * distance_ratio, 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles @@ -317,7 +303,7 @@ void main() { size *= perspective_ratio; - const float fontScale = tile.is_text ? size / 24.0 : size; + const float fontScale = drawable.is_text_prop ? size / 24.0 : size; float symbol_rotation = 0.0; if (drawable.rotate_symbol) { @@ -328,7 +314,7 @@ void main() { const vec2 a = projectedPoint.xy / projectedPoint.w; const vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; - symbol_rotation = atan((b.y - a.y) / global.aspect_ratio, b.x - a.x); + symbol_rotation = atan((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); } const float angle_sin = sin(segment_angle + symbol_rotation); @@ -342,7 +328,7 @@ void main() { applySurfaceTransform(); const vec2 raw_fade_opacity = unpack_opacity(in_fade_opacity); - const float fade_change = raw_fade_opacity[1] > 0.5 ? global.symbol_fade_change : -global.symbol_fade_change; + const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; frag_tex = a_tex / drawable.texsize; frag_fade_opacity = max(0.0, min(1.0, raw_fade_opacity[0] + fade_change)); @@ -350,19 +336,19 @@ void main() { frag_gamma_scale = gl_Position.w; #if !defined(HAS_UNIFORM_u_fill_color) - frag_fill_color = unpack_mix_color(in_fill_color, interp.fill_color_t); + frag_fill_color = unpack_mix_color(in_fill_color, drawable.fill_color_t); #endif #if !defined(HAS_UNIFORM_u_halo_color) - frag_halo_color = unpack_mix_color(in_halo_color, interp.halo_color_t); + frag_halo_color = unpack_mix_color(in_halo_color, drawable.halo_color_t); #endif #if !defined(HAS_UNIFORM_u_halo_width) - frag_halo_width = unpack_mix_float(in_halo_width, interp.halo_width_t); + frag_halo_width = unpack_mix_float(in_halo_width, drawable.halo_width_t); #endif #if !defined(HAS_UNIFORM_u_halo_blur) - frag_halo_blur = unpack_mix_float(in_halo_blur, interp.halo_blur_t); + frag_halo_blur = unpack_mix_float(in_halo_blur, drawable.halo_blur_t); #endif #if !defined(HAS_UNIFORM_u_opacity) - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif } )"; @@ -396,27 +382,12 @@ layout(location = 8) in mediump float frag_halo_blur; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform SymbolDrawableUBO { - mat4 matrix; - mat4 label_plane_matrix; - mat4 coord_matrix; - vec2 texsize; - vec2 texsize_icon; - float gamma_scale; - bool rotate_symbol; - vec2 pad; -} drawable; - layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { bool is_text; bool is_halo; - bool pitch_with_map; - bool is_size_zoom_constant; - bool is_size_feature_constant; - float size_t; - float size; - float padding; -} tile; + float gamma_scale; + float pad1; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; @@ -443,36 +414,36 @@ void main() { #endif #if defined(HAS_UNIFORM_u_fill_color) - const vec4 fill_color = tile.is_text ? props.text_fill_color : props.icon_fill_color; + const vec4 fill_color = tileProps.is_text ? props.text_fill_color : props.icon_fill_color; #else const vec4 fill_color = frag_fill_color; #endif #if defined(HAS_UNIFORM_u_halo_color) - const vec4 halo_color = tile.is_text ? props.text_halo_color : props.icon_halo_color; + const vec4 halo_color = tileProps.is_text ? props.text_halo_color : props.icon_halo_color; #else const vec4 halo_color = frag_halo_color; #endif #if defined(HAS_UNIFORM_u_opacity) - const float opacity = tile.is_text ? props.text_opacity : props.icon_opacity; + const float opacity = tileProps.is_text ? props.text_opacity : props.icon_opacity; #else const float opacity = frag_opacity; #endif #if defined(HAS_UNIFORM_u_halo_width) - const float halo_width = tile.is_text ? props.text_halo_width : props.icon_halo_width; + const float halo_width = tileProps.is_text ? props.text_halo_width : props.icon_halo_width; #else const float halo_width = frag_halo_width; #endif #if defined(HAS_UNIFORM_u_halo_blur) - const float halo_blur = tile.is_text ? props.text_halo_blur : props.icon_halo_blur; + const float halo_blur = tileProps.is_text ? props.text_halo_blur : props.icon_halo_blur; #else const float halo_blur = frag_halo_blur; #endif const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO; - const float fontGamma = frag_font_scale * drawable.gamma_scale; - const vec4 color = tile.is_halo ? halo_color : fill_color; - const float gamma = ((tile.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; - const float buff = tile.is_halo ? (6.0 - halo_width / frag_font_scale) / SDF_PX : (256.0 - 64.0) / 256.0; + const float fontGamma = frag_font_scale * tileProps.gamma_scale; + const vec4 color = tileProps.is_halo ? halo_color : fill_color; + const float gamma = ((tileProps.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; + const float buff = tileProps.is_halo ? (6.0 - halo_width / frag_font_scale) / SDF_PX : (256.0 - 64.0) / 256.0; const float dist = texture(image0_sampler, frag_tex).a; const float gamma_scaled = gamma * frag_gamma_scale; const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); @@ -486,7 +457,7 @@ template <> struct ShaderSource { static constexpr const char* name = "SymbolTextAndIconShader"; - static const std::array uniforms; + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -525,32 +496,27 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; + vec2 texsize; vec2 texsize_icon; - float gamma_scale; - bool rotate_symbol; - vec2 pad; -} drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { - bool is_text; - bool is_halo; + bool is_text_prop; + bool rotate_symbol; bool pitch_with_map; bool is_size_zoom_constant; bool is_size_feature_constant; + float size_t; float size; - float padding; -} tile; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 2) uniform SymbolInterpolateUBO { + // Interpolations float fill_color_t; float halo_color_t; float opacity_t; float halo_width_t; float halo_blur_t; - float pad1, pad2, pad3; -} interp; + float pad1; +} drawable; layout(location = 0) out mediump vec2 frag_tex; layout(location = 1) out mediump float frag_fade_opacity; @@ -592,12 +558,12 @@ void main() { const float segment_angle = -in_projected_pos[2]; float size; - if (!tile.is_size_zoom_constant && !tile.is_size_feature_constant) { - size = mix(a_size_min, a_size[1], tile.size_t) / 128.0; - } else if (tile.is_size_zoom_constant && !tile.is_size_feature_constant) { + if (!drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { + size = mix(a_size_min, a_size[1], drawable.size_t) / 128.0; + } else if (drawable.is_size_zoom_constant && !drawable.is_size_feature_constant) { size = a_size_min / 128.0; } else { - size = tile.size; + size = drawable.size; } const vec4 projectedPoint = drawable.matrix * vec4(a_pos, 0, 1); @@ -608,9 +574,9 @@ void main() { // If the label isn't pitched with the map, we do layout in viewport space, // which makes labels in the distance larger relative to the features around // them. We counteract part of that effect by dividing by the perspective ratio. - const float distance_ratio = tile.pitch_with_map ? - camera_to_anchor_distance / global.camera_to_center_distance : - global.camera_to_center_distance / camera_to_anchor_distance; + const float distance_ratio = drawable.pitch_with_map ? + camera_to_anchor_distance / paintParams.camera_to_center_distance : + paintParams.camera_to_center_distance / camera_to_anchor_distance; const float perspective_ratio = clamp( 0.5 + 0.5 * distance_ratio, 0.0, // Prevents oversized near-field symbols in pitched/overzoomed tiles @@ -629,7 +595,7 @@ void main() { const vec2 a = projectedPoint.xy / projectedPoint.w; const vec2 b = offsetProjectedPoint.xy / offsetProjectedPoint.w; - symbol_rotation = atan((b.y - a.y) / global.aspect_ratio, b.x - a.x); + symbol_rotation = atan((b.y - a.y) / paintParams.aspect_ratio, b.x - a.x); } const float angle_sin = sin(segment_angle + symbol_rotation); @@ -643,7 +609,7 @@ void main() { applySurfaceTransform(); const vec2 raw_fade_opacity = unpack_opacity(in_fade_opacity); - const float fade_change = raw_fade_opacity[1] > 0.5 ? global.symbol_fade_change : -global.symbol_fade_change; + const float fade_change = raw_fade_opacity[1] > 0.5 ? paintParams.symbol_fade_change : -paintParams.symbol_fade_change; const bool is_icon = (is_sdf == ICON); frag_is_icon = int(is_icon); @@ -654,19 +620,19 @@ void main() { frag_gamma_scale = gl_Position.w; #if !defined(HAS_UNIFORM_u_fill_color) - frag_fill_color = unpack_mix_color(in_fill_color, interp.fill_color_t); + frag_fill_color = unpack_mix_color(in_fill_color, drawable.fill_color_t); #endif #if !defined(HAS_UNIFORM_u_halo_color) - frag_halo_color = unpack_mix_color(in_halo_color, interp.halo_color_t); + frag_halo_color = unpack_mix_color(in_halo_color, drawable.halo_color_t); #endif #if !defined(HAS_UNIFORM_u_halo_width) - frag_halo_width = unpack_mix_float(in_halo_width, interp.halo_width_t); + frag_halo_width = unpack_mix_float(in_halo_width, drawable.halo_width_t); #endif #if !defined(HAS_UNIFORM_u_halo_blur) - frag_halo_blur = unpack_mix_float(in_halo_blur, interp.halo_blur_t); + frag_halo_blur = unpack_mix_float(in_halo_blur, drawable.halo_blur_t); #endif #if !defined(HAS_UNIFORM_u_opacity) - frag_opacity = unpack_mix_float(in_opacity, interp.opacity_t); + frag_opacity = unpack_mix_float(in_opacity, drawable.opacity_t); #endif } )"; @@ -702,27 +668,12 @@ layout(location = 9) flat in int frag_is_icon; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform SymbolDrawableUBO { - mat4 matrix; - mat4 label_plane_matrix; - mat4 coord_matrix; - vec2 texsize; - vec2 texsize_icon; - float gamma_scale; - bool rotate_symbol; - vec2 pad; -} drawable; - layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { bool is_text; bool is_halo; - bool pitch_with_map; - bool is_size_zoom_constant; - bool is_size_feature_constant; - float size_t; - float size; - float padding; -} tile; + float gamma_scale; + float pad1; +} tileProps; layout(set = LAYER_SET_INDEX, binding = 0) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; @@ -749,27 +700,27 @@ void main() { #endif #if defined(HAS_UNIFORM_u_fill_color) - const vec4 fill_color = tile.is_text ? props.text_fill_color : props.icon_fill_color; + const vec4 fill_color = tileProps.is_text ? props.text_fill_color : props.icon_fill_color; #else const vec4 fill_color = frag_fill_color; #endif #if defined(HAS_UNIFORM_u_halo_color) - const vec4 halo_color = tile.is_text ? props.text_halo_color : props.icon_halo_color; + const vec4 halo_color = tileProps.is_text ? props.text_halo_color : props.icon_halo_color; #else const vec4 halo_color = frag_halo_color; #endif #if defined(HAS_UNIFORM_u_opacity) - const float opacity = tile.is_text ? props.text_opacity : props.icon_opacity; + const float opacity = tileProps.is_text ? props.text_opacity : props.icon_opacity; #else const float opacity = frag_opacity; #endif #if defined(HAS_UNIFORM_u_halo_width) - const float halo_width = tile.is_text ? props.text_halo_width : props.icon_halo_width; + const float halo_width = tileProps.is_text ? props.text_halo_width : props.icon_halo_width; #else const float halo_width = frag_halo_width; #endif #if defined(HAS_UNIFORM_u_halo_blur) - const float halo_blur = tile.is_text ? props.text_halo_blur : props.icon_halo_blur; + const float halo_blur = tileProps.is_text ? props.text_halo_blur : props.icon_halo_blur; #else const float halo_blur = frag_halo_blur; #endif @@ -781,10 +732,10 @@ void main() { } const float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO; - const float fontGamma = frag_font_scale * drawable.gamma_scale; - const vec4 color = tile.is_halo ? halo_color : fill_color; - const float gamma = ((tile.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; - const float buff = tile.is_halo ? (6.0 - halo_width / frag_font_scale) / SDF_PX : (256.0 - 64.0) / 256.0; + const float fontGamma = frag_font_scale * tileProps.gamma_scale; + const vec4 color = tileProps.is_halo ? halo_color : fill_color; + const float gamma = ((tileProps.is_halo ? (halo_blur * 1.19 / SDF_PX) : 0) + EDGE_GAMMA) / fontGamma; + const float buff = tileProps.is_halo ? (6.0 - halo_width / frag_font_scale) / SDF_PX : (256.0 - 64.0) / 256.0; const float dist = texture(glyph_image, frag_tex).a; const float gamma_scaled = gamma * frag_gamma_scale; const float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist); @@ -794,97 +745,5 @@ void main() { )"; }; -template <> -struct ShaderSource { - static constexpr const char* name = "CustomSymbolIconShader"; - - static const std::array uniforms; - static const std::array attributes; - static constexpr std::array instanceAttributes{}; - static const std::array textures; - - static constexpr auto vertex = R"( - -layout(location = 0) in vec2 in_position; -layout(location = 1) in vec2 in_tex; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CustomSymbolIconDrawableUBO { - mat4 matrix; -} drawable; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CustomSymbolIconParametersUBO { - vec2 extrude_scale; - vec2 anchor; - float angle_degrees; - bool scale_with_map; - bool pitch_with_map; - float camera_to_center_distance; - float aspect_ratio; - float pad0, pad1, pad3; -} parameters; - -layout(location = 0) out vec2 frag_tex; - -vec2 rotateVec2(vec2 v, float angle) { - float cosA = cos(angle); - float sinA = sin(angle); - return vec2(v.x * cosA - v.y * sinA, v.x * sinA + v.y * cosA); -} - -vec2 ellipseRotateVec2(vec2 v, float angle, float radiusRatio /* A/B */) { - float cosA = cos(angle); - float sinA = sin(angle); - float invRatio = 1.0 / radiusRatio; - return vec2(v.x * cosA - radiusRatio * v.y * sinA, invRatio * v.x * sinA + v.y * cosA); -} - -void main() { - const vec2 extrude = mod(in_position, 2.0) * 2.0 - 1.0; - const vec2 anchor = (parameters.anchor - vec2(0.5, 0.5)) * 2.0; - const vec2 center = floor(in_position * 0.5); - const float angle = radians(-parameters.angle_degrees); - vec2 corner = extrude - anchor; - - vec4 position; - if (parameters.pitch_with_map) { - if (parameters.scale_with_map) { - corner *= parameters.extrude_scale; - } else { - vec4 projected_center = drawable.matrix * vec4(center, 0, 1); - corner *= parameters.extrude_scale * (projected_center.w / parameters.camera_to_center_distance); - } - corner = center + rotateVec2(corner, angle); - position = drawable.matrix * vec4(corner, 0, 1); - } else { - position = drawable.matrix * vec4(center, 0, 1); - const float factor = parameters.scale_with_map ? parameters.camera_to_center_distance : position.w; - position.xy += ellipseRotateVec2(corner * parameters.extrude_scale * factor, angle, parameters.aspect_ratio); - } - - gl_Position = position; - applySurfaceTransform(); - - frag_tex = in_tex; -} -)"; - - static constexpr auto fragment = R"( -layout(location = 0) in vec2 frag_tex; -layout(location = 0) out vec4 out_color; - -layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; - -void main() { - -#if defined(OVERDRAW_INSPECTOR) - out_color = vec4(1.0); - return; -#endif - - out_color = texture(image_sampler, frag_tex); -} -)"; -}; - } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/vulkan/widevector.hpp b/include/mbgl/shaders/vulkan/widevector.hpp index 5db551478fa..09faf660108 100644 --- a/include/mbgl/shaders/vulkan/widevector.hpp +++ b/include/mbgl/shaders/vulkan/widevector.hpp @@ -13,7 +13,7 @@ struct ShaderSource { static const std::array uniforms; static const std::array attributes; static const std::array instanceAttributes; - static constexpr std::array textures{}; + static const std::array textures; static constexpr auto vertex = R"( diff --git a/include/mbgl/shaders/widevector_ubo.hpp b/include/mbgl/shaders/widevector_ubo.hpp index 5842a42f23e..8720dccf728 100644 --- a/include/mbgl/shaders/widevector_ubo.hpp +++ b/include/mbgl/shaders/widevector_ubo.hpp @@ -6,30 +6,35 @@ namespace mbgl { namespace shaders { struct alignas(16) WideVectorUniformsUBO { - std::array mvpMatrix; - std::array mvpMatrixDiff; - std::array mvMatrix; - std::array mvMatrixDiff; - std::array pMatrix; - std::array pMatrixDiff; - std::array frameSize; + /* 0 */ std::array mvpMatrix; + /* 64 */ std::array mvpMatrixDiff; + /* 128 */ std::array mvMatrix; + /* 192 */ std::array mvMatrixDiff; + /* 256 */ std::array pMatrix; + /* 320 */ std::array pMatrixDiff; + /* 384 */ std::array frameSize; + /* 392 */ float pad1; + /* 396 */ float pad2; + /* 400 */ }; -static_assert(sizeof(WideVectorUniformsUBO) % 16 == 0); +static_assert(sizeof(WideVectorUniformsUBO) == 25 * 16); struct alignas(16) WideVectorUniformWideVecUBO { - std::array color; - float w2; - float offset; - float edge; - float texRepeat; - std::array texOffset; - float miterLimit; - int32_t join; - int32_t cap; - int32_t hasExp; - float interClipLimit; + /* 0 */ std::array color; + /* 16 */ float w2; + /* 20 */ float offset; + /* 24 */ float edge; + /* 28 */ float texRepeat; + /* 32 */ std::array texOffset; + /* 40 */ float miterLimit; + /* 44 */ int32_t join; + /* 48 */ int32_t cap; + /* 52 */ int32_t hasExp; + /* 56 */ float interClipLimit; + /* 60 */ float pad1; + /* 64 */ }; -static_assert(sizeof(WideVectorUniformWideVecUBO) % 16 == 0); +static_assert(sizeof(WideVectorUniformWideVecUBO) == 4 * 16); struct VertexTriWideVecB { // x, y offset around the center @@ -44,7 +49,7 @@ struct VertexTriWideVecInstance { std::array color; int32_t prev; int32_t next; - int64_t pad_; + int64_t pad1; }; static_assert(sizeof(VertexTriWideVecInstance) == 48); diff --git a/include/mbgl/vulkan/uniform_buffer.hpp b/include/mbgl/vulkan/uniform_buffer.hpp index 83854bee3a2..4b9b0ebf64c 100644 --- a/include/mbgl/vulkan/uniform_buffer.hpp +++ b/include/mbgl/vulkan/uniform_buffer.hpp @@ -51,10 +51,10 @@ class UniformBufferArray final : public gfx::UniformBufferArray { ~UniformBufferArray() = default; const std::shared_ptr& set(const size_t id, - std::shared_ptr uniformBuffer) override; + std::shared_ptr uniformBuffer, bool bindVertex, bool bindFragment) override; void createOrUpdate( - const size_t id, const void* data, std::size_t size, gfx::Context& context, bool persistent = false) override; + const size_t id, const void* data, std::size_t size, gfx::Context& context, bool bindVertex, bool bindFragment) override; void bindDescriptorSets(CommandEncoder& encoder); void freeDescriptorSets() { descriptorSet.reset(); } diff --git a/shaders/drawable.background.fragment.glsl b/shaders/drawable.background.fragment.glsl index 383012d37ef..2b55c4991b8 100644 --- a/shaders/drawable.background.fragment.glsl +++ b/shaders/drawable.background.fragment.glsl @@ -1,7 +1,9 @@ -layout (std140) uniform BackgroundLayerUBO { +layout (std140) uniform BackgroundPropsUBO { highp vec4 u_color; highp float u_opacity; - highp float layer_pad1, layer_pad2, layer_pad3; + lowp float props_pad1; + lowp float props_pad2; + lowp float props_pad3; }; void main() { diff --git a/shaders/drawable.background_pattern.fragment.glsl b/shaders/drawable.background_pattern.fragment.glsl index f8ef5e7a567..8729d5d6254 100644 --- a/shaders/drawable.background_pattern.fragment.glsl +++ b/shaders/drawable.background_pattern.fragment.glsl @@ -6,10 +6,11 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; -layout (std140) uniform BackgroundPatternLayerUBO { +layout (std140) uniform BackgroundPatternPropsUBO { highp vec2 u_pattern_tl_a; highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; diff --git a/shaders/drawable.background_pattern.vertex.glsl b/shaders/drawable.background_pattern.vertex.glsl index 5147bcbba61..1341c0651ae 100644 --- a/shaders/drawable.background_pattern.vertex.glsl +++ b/shaders/drawable.background_pattern.vertex.glsl @@ -3,9 +3,12 @@ layout (std140) uniform BackgroundPatternDrawableUBO { highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_tile_units_to_pixels; - highp float drawable_pad1, drawable_pad2, drawable_pad3; + lowp float drawable_pad1; + lowp float drawable_pad2; + lowp float drawable_pad3; }; -layout (std140) uniform BackgroundPatternLayerUBO { + +layout (std140) uniform BackgroundPatternPropsUBO { highp vec2 u_pattern_tl_a; highp vec2 u_pattern_br_a; highp vec2 u_pattern_tl_b; diff --git a/shaders/drawable.circle.vertex.glsl b/shaders/drawable.circle.vertex.glsl index b3bcd07a133..a6c16eea5ac 100644 --- a/shaders/drawable.circle.vertex.glsl +++ b/shaders/drawable.circle.vertex.glsl @@ -9,13 +9,24 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform CircleDrawableUBO { highp mat4 u_matrix; highp vec2 u_extrude_scale; - lowp vec2 drawable_pad1; + // Interpolations + lowp float u_color_t; + lowp float u_radius_t; + lowp float u_blur_t; + lowp float u_opacity_t; + lowp float u_stroke_color_t; + lowp float u_stroke_width_t; + lowp float u_stroke_opacity_t; + lowp float drawable_pad1; + lowp float drawable_pad2; + lowp float drawable_pad3; }; layout (std140) uniform CircleEvaluatedPropsUBO { @@ -31,17 +42,6 @@ layout (std140) uniform CircleEvaluatedPropsUBO { lowp float props_pad1; }; -layout (std140) uniform CircleInterpolateUBO { - lowp float u_color_t; - lowp float u_radius_t; - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_stroke_color_t; - lowp float u_stroke_width_t; - lowp float u_stroke_opacity_t; - lowp float interp_pad1; -}; - #pragma mapbox: define highp vec4 color #pragma mapbox: define mediump float radius #pragma mapbox: define lowp float blur diff --git a/shaders/drawable.collision_box.fragment.glsl b/shaders/drawable.collision_box.fragment.glsl index 81be488d0f0..582a2798194 100644 --- a/shaders/drawable.collision_box.fragment.glsl +++ b/shaders/drawable.collision_box.fragment.glsl @@ -1,10 +1,3 @@ -layout (std140) uniform CollisionUBO { - highp mat4 u_matrix; - highp vec2 u_extrude_scale; - highp float u_overscale_factor; - highp float pad1; -}; - in float v_placed; in float v_notUsed; diff --git a/shaders/drawable.collision_box.vertex.glsl b/shaders/drawable.collision_box.vertex.glsl index da1ddd39394..eca7f956862 100644 --- a/shaders/drawable.collision_box.vertex.glsl +++ b/shaders/drawable.collision_box.vertex.glsl @@ -12,14 +12,18 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; -layout (std140) uniform CollisionUBO { +layout (std140) uniform CollisionDrawableUBO { highp mat4 u_matrix; +}; + +layout (std140) uniform CollisionTilePropsUBO { highp vec2 u_extrude_scale; highp float u_overscale_factor; - highp float pad1; + lowp float drawable_pad1; }; out float v_placed; diff --git a/shaders/drawable.collision_circle.fragment.glsl b/shaders/drawable.collision_circle.fragment.glsl index 338070a2b4d..611cf6b9cac 100644 --- a/shaders/drawable.collision_circle.fragment.glsl +++ b/shaders/drawable.collision_circle.fragment.glsl @@ -6,14 +6,14 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; -layout (std140) uniform CollisionUBO { - highp mat4 u_matrix; +layout (std140) uniform CollisionTilePropsUBO { highp vec2 u_extrude_scale; highp float u_overscale_factor; - highp float pad1; + lowp float drawable_pad1; }; in float v_placed; diff --git a/shaders/drawable.collision_circle.vertex.glsl b/shaders/drawable.collision_circle.vertex.glsl index 92f325c8fe3..2cc20f008b1 100644 --- a/shaders/drawable.collision_circle.vertex.glsl +++ b/shaders/drawable.collision_circle.vertex.glsl @@ -11,14 +11,18 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; -layout (std140) uniform CollisionUBO { +layout (std140) uniform CollisionDrawableUBO { highp mat4 u_matrix; +}; + +layout (std140) uniform CollisionTilePropsUBO { highp vec2 u_extrude_scale; highp float u_overscale_factor; - highp float pad1; + lowp float drawable_pad1; }; out float v_placed; diff --git a/shaders/drawable.custom.symbol_icon.vertex.glsl b/shaders/drawable.custom.symbol_icon.vertex.glsl index 3343923b6fd..8f514e2ed15 100644 --- a/shaders/drawable.custom.symbol_icon.vertex.glsl +++ b/shaders/drawable.custom.symbol_icon.vertex.glsl @@ -3,9 +3,6 @@ layout(location = 1) in vec2 a_tex; layout(std140) uniform CustomSymbolIconDrawableUBO { highp mat4 u_matrix; -}; - -layout(std140) uniform CustomSymbolIconParametersUBO { highp vec2 u_extrude_scale; highp vec2 u_anchor; highp float u_angle_degrees; @@ -13,7 +10,9 @@ layout(std140) uniform CustomSymbolIconParametersUBO { bool u_pitch_with_map; highp float u_camera_to_center_distance; highp float u_aspect_ratio; - highp float params_pad1, params_pad2, params_pad3; + lowp float drawable_pad1; + lowp float drawable_pad2; + lowp float drawable_pad3; }; out vec2 v_tex; diff --git a/shaders/drawable.debug.fragment.glsl b/shaders/drawable.debug.fragment.glsl index 4b197f541f9..2376634a881 100644 --- a/shaders/drawable.debug.fragment.glsl +++ b/shaders/drawable.debug.fragment.glsl @@ -2,9 +2,9 @@ layout (std140) uniform DebugUBO { highp mat4 u_matrix; highp vec4 u_color; highp float u_overlay_scale; - highp float pad1; - highp float pad2; - highp float pad3; + lowp float pad1; + lowp float pad2; + lowp float pad3; }; uniform sampler2D u_overlay; diff --git a/shaders/drawable.debug.vertex.glsl b/shaders/drawable.debug.vertex.glsl index 20b10f2dbd3..10236b141f2 100644 --- a/shaders/drawable.debug.vertex.glsl +++ b/shaders/drawable.debug.vertex.glsl @@ -5,9 +5,9 @@ layout (std140) uniform DebugUBO { highp mat4 u_matrix; highp vec4 u_color; highp float u_overlay_scale; - highp float pad1; - highp float pad2; - highp float pad3; + lowp float pad1; + lowp float pad2; + lowp float pad3; }; void main() { diff --git a/shaders/drawable.fill.fragment.glsl b/shaders/drawable.fill.fragment.glsl index 0e0aed6c7d8..cd2d2aa4a80 100644 --- a/shaders/drawable.fill.fragment.glsl +++ b/shaders/drawable.fill.fragment.glsl @@ -1,8 +1,3 @@ -layout (std140) uniform FillInterpolateUBO { - highp float u_color_t; - highp float u_opacity_t; - highp float interp_pad1, interp_pad2; -}; layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.fill.vertex.glsl b/shaders/drawable.fill.vertex.glsl index caffecd545e..f77883221c9 100644 --- a/shaders/drawable.fill.vertex.glsl +++ b/shaders/drawable.fill.vertex.glsl @@ -1,11 +1,12 @@ layout (std140) uniform FillDrawableUBO { highp mat4 u_matrix; -}; -layout (std140) uniform FillInterpolateUBO { + // Interpolations highp float u_color_t; highp float u_opacity_t; - highp float interp_pad1, interp_pad2; + lowp float drawable_pad1; + lowp float drawable_pad2; }; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.fill_extrusion.vertex.glsl b/shaders/drawable.fill_extrusion.vertex.glsl index 79c7429bdac..ae4dc60fd26 100644 --- a/shaders/drawable.fill_extrusion.vertex.glsl +++ b/shaders/drawable.fill_extrusion.vertex.glsl @@ -4,16 +4,31 @@ out vec4 v_color; layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; highp float u_tile_ratio; + // Interpolations + highp float u_base_t; + highp float u_height_t; + highp float u_color_t; + highp float u_pattern_from_t; + highp float u_pattern_to_t; + lowp float drawable_pad1; +}; + +layout (std140) uniform FillExtrusionTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; + layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; highp vec3 u_lightcolor; - highp float props_pad1; + lowp float props_pad1; highp vec3 u_lightpos; highp float u_base; highp float u_height; @@ -23,20 +38,9 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_fade; highp float u_from_scale; highp float u_to_scale; - highp float props_pad2; -}; -layout (std140) uniform FillExtrusionTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; -}; -layout (std140) uniform FillExtrusionInterpolateUBO { - highp float u_base_t; - highp float u_height_t; - highp float u_color_t; - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float interp_pad1, interp_pad2, interp_pad3; + lowp float props_pad2; }; + #pragma mapbox: define highp float base #pragma mapbox: define highp float height #pragma mapbox: define highp vec4 color diff --git a/shaders/drawable.fill_extrusion_pattern.fragment.glsl b/shaders/drawable.fill_extrusion_pattern.fragment.glsl index 0f6d4b717b0..a4ce886e3d9 100644 --- a/shaders/drawable.fill_extrusion_pattern.fragment.glsl +++ b/shaders/drawable.fill_extrusion_pattern.fragment.glsl @@ -2,18 +2,18 @@ in vec2 v_pos_a; in vec2 v_pos_b; in vec4 v_lighting; -layout (std140) uniform FillExtrusionDrawableUBO { - highp mat4 u_matrix; +layout (std140) uniform FillExtrusionTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; highp vec2 u_texsize; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp float u_height_factor; - highp float u_tile_ratio; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; + layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; highp vec3 u_lightcolor; - highp float props_pad1; + lowp float props_pad1; highp vec3 u_lightpos; highp float u_base; highp float u_height; @@ -23,19 +23,7 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_fade; highp float u_from_scale; highp float u_to_scale; - highp float props_pad2; -}; -layout (std140) uniform FillExtrusionTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; -}; -layout (std140) uniform FillExtrusionInterpolateUBO { - highp float u_base_t; - highp float u_height_t; - highp float u_color_t; - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float interp_pad1, interp_pad2, interp_pad3; + lowp float props_pad2; }; uniform sampler2D u_image; diff --git a/shaders/drawable.fill_extrusion_pattern.vertex.glsl b/shaders/drawable.fill_extrusion_pattern.vertex.glsl index bc0d9b09bf0..71645f7f3df 100644 --- a/shaders/drawable.fill_extrusion_pattern.vertex.glsl +++ b/shaders/drawable.fill_extrusion_pattern.vertex.glsl @@ -13,21 +13,37 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform FillExtrusionDrawableUBO { highp mat4 u_matrix; - highp vec2 u_texsize; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; highp float u_height_factor; highp float u_tile_ratio; + // Interpolations + highp float u_base_t; + highp float u_height_t; + highp float u_color_t; + highp float u_pattern_from_t; + highp float u_pattern_to_t; + lowp float drawable_pad1; +}; + +layout (std140) uniform FillExtrusionTilePropsUBO { + highp vec4 u_pattern_from; + highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; + layout (std140) uniform FillExtrusionPropsUBO { highp vec4 u_color; highp vec3 u_lightcolor; - highp float props_pad1; + lowp float props_pad1; highp vec3 u_lightpos; highp float u_base; highp float u_height; @@ -37,19 +53,7 @@ layout (std140) uniform FillExtrusionPropsUBO { highp float u_fade; highp float u_from_scale; highp float u_to_scale; - highp float props_pad2; -}; -layout (std140) uniform FillExtrusionTilePropsUBO { - highp vec4 u_pattern_from; - highp vec4 u_pattern_to; -}; -layout (std140) uniform FillExtrusionInterpolateUBO { - highp float u_base_t; - highp float u_height_t; - highp float u_color_t; - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float interp_pad1, interp_pad2, interp_pad3; + lowp float props_pad2; }; #pragma mapbox: define lowp float base diff --git a/shaders/drawable.fill_outline.fragment.glsl b/shaders/drawable.fill_outline.fragment.glsl index 2b795274a65..eacab766499 100644 --- a/shaders/drawable.fill_outline.fragment.glsl +++ b/shaders/drawable.fill_outline.fragment.glsl @@ -1,9 +1,3 @@ -layout (std140) uniform FillOutlineInterpolateUBO { - highp float u_outline_color_t; - highp float u_opacity_t; - highp float interp_pad1; - highp float interp_pad2; -}; layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.fill_outline.vertex.glsl b/shaders/drawable.fill_outline.vertex.glsl index 9e255d162fb..50dadb4c3dd 100644 --- a/shaders/drawable.fill_outline.vertex.glsl +++ b/shaders/drawable.fill_outline.vertex.glsl @@ -6,17 +6,19 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; + layout (std140) uniform FillOutlineDrawableUBO { highp mat4 u_matrix; -}; -layout (std140) uniform FillOutlineInterpolateUBO { + // Interpolations highp float u_outline_color_t; highp float u_opacity_t; - highp float interp_pad1; - highp float interp_pad2; + lowp float drawable_pad1; + lowp float drawable_pad2; }; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.fill_outline_pattern.fragment.glsl b/shaders/drawable.fill_outline_pattern.fragment.glsl index 21c8a683adb..7e617540168 100644 --- a/shaders/drawable.fill_outline_pattern.fragment.glsl +++ b/shaders/drawable.fill_outline_pattern.fragment.glsl @@ -1,21 +1,11 @@ -layout (std140) uniform FillOutlinePatternDrawableUBO { - highp mat4 u_matrix; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp vec2 u_texsize; - highp float u_tile_ratio; - highp float drawable_pad1; -}; layout (std140) uniform FillOutlinePatternTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; -layout (std140) uniform FillOutlinePatternInterpolateUBO { - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float u_opacity_t; - highp float interp_pad1; -}; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.fill_outline_pattern.vertex.glsl b/shaders/drawable.fill_outline_pattern.vertex.glsl index d7be97bf87a..ebedb8cd0fc 100644 --- a/shaders/drawable.fill_outline_pattern.vertex.glsl +++ b/shaders/drawable.fill_outline_pattern.vertex.glsl @@ -6,26 +6,29 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; + layout (std140) uniform FillOutlinePatternDrawableUBO { highp mat4 u_matrix; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; - highp vec2 u_texsize; highp float u_tile_ratio; - highp float drawable_pad1; + // Interpolations + highp float u_pattern_from_t; + highp float u_pattern_to_t; + highp float u_opacity_t; }; + layout (std140) uniform FillOutlinePatternTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; -layout (std140) uniform FillOutlinePatternInterpolateUBO { - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float u_opacity_t; - highp float interp_pad1; -}; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.fill_outline_triangulated.vertex.glsl b/shaders/drawable.fill_outline_triangulated.vertex.glsl index 4ce24cda23e..a2ca7e57415 100644 --- a/shaders/drawable.fill_outline_triangulated.vertex.glsl +++ b/shaders/drawable.fill_outline_triangulated.vertex.glsl @@ -17,13 +17,18 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; + layout (std140) uniform FillOutlineTriangulatedDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; + lowp float drawable_pad1; + lowp float drawable_pad2; + lowp float drawable_pad3; }; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.fill_pattern.fragment.glsl b/shaders/drawable.fill_pattern.fragment.glsl index 54b657cce66..37f2d0caaf6 100644 --- a/shaders/drawable.fill_pattern.fragment.glsl +++ b/shaders/drawable.fill_pattern.fragment.glsl @@ -1,21 +1,11 @@ -layout (std140) uniform FillPatternDrawableUBO { - highp mat4 u_matrix; - highp vec2 u_pixel_coord_upper; - highp vec2 u_pixel_coord_lower; - highp vec2 u_texsize; - highp float u_tile_ratio; - highp float drawable_pad1; -}; layout (std140) uniform FillPatternTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; -layout (std140) uniform FillPatternInterpolateUBO { - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float u_opacity_t; - highp float interp_pad1; -}; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.fill_pattern.vertex.glsl b/shaders/drawable.fill_pattern.vertex.glsl index ba738168eef..574ac994e24 100644 --- a/shaders/drawable.fill_pattern.vertex.glsl +++ b/shaders/drawable.fill_pattern.vertex.glsl @@ -6,26 +6,29 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; + layout (std140) uniform FillPatternDrawableUBO { highp mat4 u_matrix; highp vec2 u_pixel_coord_upper; highp vec2 u_pixel_coord_lower; - highp vec2 u_texsize; highp float u_tile_ratio; - highp float drawable_pad1; + // Interpolations + highp float u_pattern_from_t; + highp float u_pattern_to_t; + highp float u_opacity_t; }; + layout (std140) uniform FillPatternTilePropsUBO { highp vec4 u_pattern_from; highp vec4 u_pattern_to; + highp vec2 u_texsize; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; -layout (std140) uniform FillPatternInterpolateUBO { - highp float u_pattern_from_t; - highp float u_pattern_to_t; - highp float u_opacity_t; - highp float interp_pad1; -}; + layout (std140) uniform FillEvaluatedPropsUBO { highp vec4 u_color; highp vec4 u_outline_color; diff --git a/shaders/drawable.heatmap.vertex.glsl b/shaders/drawable.heatmap.vertex.glsl index d769d5ef4dc..430b428b160 100644 --- a/shaders/drawable.heatmap.vertex.glsl +++ b/shaders/drawable.heatmap.vertex.glsl @@ -4,8 +4,10 @@ out vec2 v_extrude; layout (std140) uniform HeatmapDrawableUBO { highp mat4 u_matrix; highp float u_extrude_scale; + // Interpolations + lowp float u_weight_t; + lowp float u_radius_t; lowp float drawable_pad1; - lowp vec2 drawable_pad2; }; layout (std140) uniform HeatmapEvaluatedPropsUBO { @@ -15,12 +17,6 @@ layout (std140) uniform HeatmapEvaluatedPropsUBO { lowp float props_pad1; }; -layout (std140) uniform HeatmapInterpolateUBO { - lowp float u_weight_t; - lowp float u_radius_t; - lowp vec2 interp_pad1; -}; - #pragma mapbox: define highp float weight #pragma mapbox: define mediump float radius diff --git a/shaders/drawable.heatmap_texture.fragment.glsl b/shaders/drawable.heatmap_texture.fragment.glsl index 0d08fa736ff..b718394c18b 100644 --- a/shaders/drawable.heatmap_texture.fragment.glsl +++ b/shaders/drawable.heatmap_texture.fragment.glsl @@ -5,7 +5,9 @@ uniform sampler2D u_color_ramp; layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; highp float u_opacity; - lowp float props_pad1, props_pad2, props_pad3; + lowp float props_pad1; + lowp float props_pad2; + lowp float props_pad3; }; void main() { diff --git a/shaders/drawable.heatmap_texture.vertex.glsl b/shaders/drawable.heatmap_texture.vertex.glsl index 272f3692453..714540473b0 100644 --- a/shaders/drawable.heatmap_texture.vertex.glsl +++ b/shaders/drawable.heatmap_texture.vertex.glsl @@ -9,12 +9,16 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; + layout (std140) uniform HeatmapTexturePropsUBO { highp mat4 u_matrix; highp float u_opacity; - lowp float props_pad1, props_pad2, props_pad3; + lowp float props_pad1; + lowp float props_pad2; + lowp float props_pad3; }; void main() { diff --git a/shaders/drawable.hillshade.fragment.glsl b/shaders/drawable.hillshade.fragment.glsl index ca3df92554f..499aa3c67d0 100644 --- a/shaders/drawable.hillshade.fragment.glsl +++ b/shaders/drawable.hillshade.fragment.glsl @@ -1,8 +1,7 @@ in vec2 v_pos; uniform sampler2D u_image; -layout (std140) uniform HillshadeDrawableUBO { - highp mat4 u_matrix; +layout (std140) uniform HillshadeTilePropsUBO { highp vec2 u_latrange; highp vec2 u_light; }; diff --git a/shaders/drawable.hillshade.vertex.glsl b/shaders/drawable.hillshade.vertex.glsl index 20fadb2f04a..acbc038036d 100644 --- a/shaders/drawable.hillshade.vertex.glsl +++ b/shaders/drawable.hillshade.vertex.glsl @@ -3,8 +3,6 @@ layout (location = 1) in vec2 a_texture_pos; layout (std140) uniform HillshadeDrawableUBO { highp mat4 u_matrix; - highp vec2 u_latrange; - highp vec2 u_light; }; out vec2 v_pos; diff --git a/shaders/drawable.hillshade_prepare.fragment.glsl b/shaders/drawable.hillshade_prepare.fragment.glsl index 8cd8009055e..9f798875009 100644 --- a/shaders/drawable.hillshade_prepare.fragment.glsl +++ b/shaders/drawable.hillshade_prepare.fragment.glsl @@ -5,8 +5,7 @@ precision highp float; in vec2 v_pos; uniform sampler2D u_image; -layout (std140) uniform HillshadePrepareDrawableUBO { - highp mat4 u_matrix; +layout (std140) uniform HillshadePrepareTilePropsUBO { highp vec4 u_unpack; highp vec2 u_dimension; highp float u_zoom; diff --git a/shaders/drawable.hillshade_prepare.vertex.glsl b/shaders/drawable.hillshade_prepare.vertex.glsl index a3aaad8d065..b917e86fdb2 100644 --- a/shaders/drawable.hillshade_prepare.vertex.glsl +++ b/shaders/drawable.hillshade_prepare.vertex.glsl @@ -3,6 +3,9 @@ layout (location = 1) in vec2 a_texture_pos; layout (std140) uniform HillshadePrepareDrawableUBO { highp mat4 u_matrix; +}; + +layout (std140) uniform HillshadePrepareTilePropsUBO { highp vec4 u_unpack; highp vec2 u_dimension; highp float u_zoom; diff --git a/shaders/drawable.line.fragment.glsl b/shaders/drawable.line.fragment.glsl index 9d80d25f7cd..0d201bd28be 100644 --- a/shaders/drawable.line.fragment.glsl +++ b/shaders/drawable.line.fragment.glsl @@ -1,19 +1,3 @@ -layout (std140) uniform LineDrawableUBO { - highp mat4 u_matrix; - mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineInterpolationUBO { - lowp float u_color_t; - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_gapwidth_t; - lowp float u_offset_t; - lowp float u_width_t; - highp vec2 interp_pad1; -}; - layout (std140) uniform LineEvaluatedPropsUBO { highp vec4 u_color; lowp float u_blur; @@ -22,8 +6,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; in vec2 v_width2; diff --git a/shaders/drawable.line.vertex.glsl b/shaders/drawable.line.vertex.glsl index da69b172c93..5dc5f87269a 100644 --- a/shaders/drawable.line.vertex.glsl +++ b/shaders/drawable.line.vertex.glsl @@ -17,23 +17,21 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform LineDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineInterpolationUBO { + // Interpolations lowp float u_color_t; lowp float u_blur_t; lowp float u_opacity_t; lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; - highp vec2 interp_pad1; + lowp float drawable_pad1; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -44,8 +42,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; out vec2 v_normal; diff --git a/shaders/drawable.line_gradient.fragment.glsl b/shaders/drawable.line_gradient.fragment.glsl index f8bec311011..a970705ab5b 100644 --- a/shaders/drawable.line_gradient.fragment.glsl +++ b/shaders/drawable.line_gradient.fragment.glsl @@ -1,19 +1,3 @@ -layout (std140) uniform LineGradientDrawableUBO { - highp mat4 u_matrix; - mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineGradientInterpolationUBO { - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_gapwidth_t; - lowp float u_offset_t; - lowp float u_width_t; - highp float interp_pad1; - highp vec2 interp_pad2; -}; - layout (std140) uniform LineEvaluatedPropsUBO { highp vec4 u_color; lowp float u_blur; @@ -22,8 +6,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; uniform sampler2D u_image; diff --git a/shaders/drawable.line_gradient.vertex.glsl b/shaders/drawable.line_gradient.vertex.glsl index 41bff822811..f521a227095 100644 --- a/shaders/drawable.line_gradient.vertex.glsl +++ b/shaders/drawable.line_gradient.vertex.glsl @@ -21,23 +21,21 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform LineGradientDrawableUBO { highp mat4 u_matrix; mediump float u_ratio; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineGradientInterpolationUBO { + // Interpolations lowp float u_blur_t; lowp float u_opacity_t; lowp float u_gapwidth_t; lowp float u_offset_t; lowp float u_width_t; - highp float interp_pad1; - highp vec2 interp_pad2; + lowp float drawable_pad1; + lowp float drawable_pad2; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -48,8 +46,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; out vec2 v_normal; diff --git a/shaders/drawable.line_pattern.fragment.glsl b/shaders/drawable.line_pattern.fragment.glsl index cbe9b11f7b4..4fbcf49ecef 100644 --- a/shaders/drawable.line_pattern.fragment.glsl +++ b/shaders/drawable.line_pattern.fragment.glsl @@ -1,25 +1,10 @@ -layout (std140) uniform LinePatternDrawableUBO { - highp mat4 u_matrix; +layout (std140) uniform LinePatternTilePropsUBO { + lowp vec4 u_pattern_from; + lowp vec4 u_pattern_to; mediump vec4 u_scale; highp vec2 u_texsize; - mediump float u_ratio; highp float u_fade; -}; - -layout (std140) uniform LinePatternInterpolationUBO { - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_offset_t; - lowp float u_gapwidth_t; - lowp float u_width_t; - lowp float u_pattern_from_t; - lowp float u_pattern_to_t; - highp float interp_pad1; -}; - -layout (std140) uniform LinePatternTilePropertiesUBO { - lowp vec4 u_pattern_from; - lowp vec4 u_pattern_to; + lowp float tileprops_pad1; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -30,8 +15,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; uniform sampler2D u_image; diff --git a/shaders/drawable.line_pattern.vertex.glsl b/shaders/drawable.line_pattern.vertex.glsl index e573d9a36f2..c42ab953d43 100644 --- a/shaders/drawable.line_pattern.vertex.glsl +++ b/shaders/drawable.line_pattern.vertex.glsl @@ -21,18 +21,13 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; - layout (std140) uniform LinePatternDrawableUBO { highp mat4 u_matrix; - mediump vec4 u_scale; - highp vec2 u_texsize; mediump float u_ratio; - highp float u_fade; -}; - -layout (std140) uniform LinePatternInterpolationUBO { + // Interpolations lowp float u_blur_t; lowp float u_opacity_t; lowp float u_offset_t; @@ -40,12 +35,15 @@ layout (std140) uniform LinePatternInterpolationUBO { lowp float u_width_t; lowp float u_pattern_from_t; lowp float u_pattern_to_t; - highp float interp_pad1; }; -layout (std140) uniform LinePatternTilePropertiesUBO { +layout (std140) uniform LinePatternTilePropsUBO { lowp vec4 u_pattern_from; lowp vec4 u_pattern_to; + mediump vec4 u_scale; + highp vec2 u_texsize; + highp float u_fade; + lowp float tileprops_pad1; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -56,8 +54,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; out vec2 v_normal; diff --git a/shaders/drawable.line_sdf.fragment.glsl b/shaders/drawable.line_sdf.fragment.glsl index 23405efd6c0..852f5f6d59a 100644 --- a/shaders/drawable.line_sdf.fragment.glsl +++ b/shaders/drawable.line_sdf.fragment.glsl @@ -1,25 +1,8 @@ - -layout (std140) uniform LineSDFDrawableUBO { - highp mat4 u_matrix; - highp vec2 u_patternscale_a; - highp vec2 u_patternscale_b; - mediump float u_ratio; - highp float u_tex_y_a; - highp float u_tex_y_b; +layout (std140) uniform LineSDFTilePropsUBO { highp float u_sdfgamma; highp float u_mix; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineSDFInterpolationUBO { - lowp float u_color_t; - lowp float u_blur_t; - lowp float u_opacity_t; - lowp float u_gapwidth_t; - lowp float u_offset_t; - lowp float u_width_t; - lowp float u_floorwidth_t; - highp float interp_pad1; + lowp float tileprops_pad1; + lowp float tileprops_pad2; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -30,8 +13,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; uniform sampler2D u_image; diff --git a/shaders/drawable.line_sdf.vertex.glsl b/shaders/drawable.line_sdf.vertex.glsl index 98ce3b981b6..434498972d6 100644 --- a/shaders/drawable.line_sdf.vertex.glsl +++ b/shaders/drawable.line_sdf.vertex.glsl @@ -21,22 +21,18 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform LineSDFDrawableUBO { highp mat4 u_matrix; highp vec2 u_patternscale_a; highp vec2 u_patternscale_b; - mediump float u_ratio; highp float u_tex_y_a; highp float u_tex_y_b; - highp float u_sdfgamma; - highp float u_mix; - lowp float drawable_pad1, drawable_pad2, drawable_pad3; -}; - -layout (std140) uniform LineSDFInterpolationUBO { + mediump float u_ratio; + // Interpolations lowp float u_color_t; lowp float u_blur_t; lowp float u_opacity_t; @@ -44,7 +40,8 @@ layout (std140) uniform LineSDFInterpolationUBO { lowp float u_offset_t; lowp float u_width_t; lowp float u_floorwidth_t; - highp float interp_pad1; + lowp float drawable_pad1; + lowp float drawable_pad2; }; layout (std140) uniform LineEvaluatedPropsUBO { @@ -55,8 +52,8 @@ layout (std140) uniform LineEvaluatedPropsUBO { lowp float u_offset; mediump float u_width; lowp float u_floorwidth; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; out vec2 v_normal; diff --git a/shaders/drawable.raster.fragment.glsl b/shaders/drawable.raster.fragment.glsl index 4264906f118..352cf5a0060 100644 --- a/shaders/drawable.raster.fragment.glsl +++ b/shaders/drawable.raster.fragment.glsl @@ -9,8 +9,8 @@ layout (std140) uniform RasterEvaluatedPropsUBO { highp float u_brightness_high; highp float u_saturation_factor; highp float u_contrast_factor; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; uniform sampler2D u_image0; uniform sampler2D u_image1; diff --git a/shaders/drawable.raster.vertex.glsl b/shaders/drawable.raster.vertex.glsl index d227fb05f2d..331f376fed8 100644 --- a/shaders/drawable.raster.vertex.glsl +++ b/shaders/drawable.raster.vertex.glsl @@ -12,8 +12,8 @@ layout (std140) uniform RasterEvaluatedPropsUBO { highp float u_brightness_high; highp float u_saturation_factor; highp float u_contrast_factor; - highp float props_pad1; - highp float props_pad2; + lowp float props_pad1; + lowp float props_pad2; }; layout (location = 0) in vec2 a_pos; diff --git a/shaders/drawable.symbol_icon.fragment.glsl b/shaders/drawable.symbol_icon.fragment.glsl index 2350acdcf13..ce3a301d52d 100644 --- a/shaders/drawable.symbol_icon.fragment.glsl +++ b/shaders/drawable.symbol_icon.fragment.glsl @@ -3,12 +3,8 @@ uniform sampler2D u_texture; layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; - bool u_pitch_with_map; - bool u_is_size_zoom_constant; - bool u_is_size_feature_constant; - highp float u_size_t; // used to interpolate between zoom stops when size is a composite function - highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; + highp float u_gamma_scale; + lowp float tileprops_pad1; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -17,13 +13,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; in vec2 v_tex; diff --git a/shaders/drawable.symbol_icon.vertex.glsl b/shaders/drawable.symbol_icon.vertex.glsl index 6bbd66d1e54..678f3323b74 100644 --- a/shaders/drawable.symbol_icon.vertex.glsl +++ b/shaders/drawable.symbol_icon.vertex.glsl @@ -12,7 +12,8 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform SymbolDrawableUBO { @@ -23,29 +24,21 @@ layout (std140) uniform SymbolDrawableUBO { highp vec2 u_texsize; highp vec2 u_texsize_icon; - highp float u_gamma_scale; + bool u_is_text_prop; bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - -layout (std140) uniform SymbolTilePropsUBO { - bool u_is_text; - bool u_is_halo; bool u_pitch_with_map; bool u_is_size_zoom_constant; bool u_is_size_feature_constant; + highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; -}; -layout (std140) uniform SymbolInterpolateUBO { + // Interpolations highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float interp_pad1, interp_pad2, interp_pad3; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -54,13 +47,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; out vec2 v_tex; @@ -69,7 +62,7 @@ out float v_fade_opacity; #pragma mapbox: define lowp float opacity void main() { - highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; + highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity; #pragma mapbox: initialize lowp float opacity @@ -107,7 +100,7 @@ void main() { size *= perspective_ratio; - float fontScale = u_is_text ? size / 24.0 : size; + float fontScale = u_is_text_prop ? size / 24.0 : size; highp float symbol_rotation = 0.0; if (u_rotate_symbol) { diff --git a/shaders/drawable.symbol_sdf.fragment.glsl b/shaders/drawable.symbol_sdf.fragment.glsl index 06385d61137..6bc97ac3e17 100644 --- a/shaders/drawable.symbol_sdf.fragment.glsl +++ b/shaders/drawable.symbol_sdf.fragment.glsl @@ -1,27 +1,10 @@ #define SDF_PX 8.0 -layout (std140) uniform SymbolDrawableUBO { - highp mat4 u_matrix; - highp mat4 u_label_plane_matrix; - highp mat4 u_coord_matrix; - - highp vec2 u_texsize; - highp vec2 u_texsize_icon; - - highp float u_gamma_scale; - bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; - bool u_pitch_with_map; - bool u_is_size_zoom_constant; - bool u_is_size_feature_constant; - highp float u_size_t; // used to interpolate between zoom stops when size is a composite function - highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; + highp float u_gamma_scale; + lowp float tileprops_pad1; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -30,13 +13,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; uniform sampler2D u_texture; diff --git a/shaders/drawable.symbol_sdf.vertex.glsl b/shaders/drawable.symbol_sdf.vertex.glsl index 64ea45be7ee..6c94980d7af 100644 --- a/shaders/drawable.symbol_sdf.vertex.glsl +++ b/shaders/drawable.symbol_sdf.vertex.glsl @@ -20,7 +20,8 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform SymbolDrawableUBO { @@ -31,29 +32,21 @@ layout (std140) uniform SymbolDrawableUBO { highp vec2 u_texsize; highp vec2 u_texsize_icon; - highp float u_gamma_scale; + bool u_is_text_prop; bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - -layout (std140) uniform SymbolTilePropsUBO { - bool u_is_text; - bool u_is_halo; bool u_pitch_with_map; bool u_is_size_zoom_constant; bool u_is_size_feature_constant; + highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; -}; -layout (std140) uniform SymbolInterpolateUBO { + // Interpolations highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float interp_pad1, interp_pad2, interp_pad3; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -62,13 +55,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; out vec2 v_data0; @@ -81,11 +74,11 @@ out vec3 v_data1; #pragma mapbox: define lowp float halo_blur void main() { - highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; - highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; - highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; - highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; - highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + highp vec4 u_fill_color = u_is_text_prop ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text_prop ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text_prop ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text_prop ? u_text_halo_blur : u_icon_halo_blur; #pragma mapbox: initialize highp vec4 fill_color #pragma mapbox: initialize highp vec4 halo_color @@ -131,7 +124,7 @@ void main() { size *= perspective_ratio; - float fontScale = u_is_text ? size / 24.0 : size; + float fontScale = u_is_text_prop ? size / 24.0 : size; highp float symbol_rotation = 0.0; if (u_rotate_symbol) { diff --git a/shaders/drawable.symbol_text_and_icon.fragment.glsl b/shaders/drawable.symbol_text_and_icon.fragment.glsl index 15a0cdbddab..8c307d0f0d4 100644 --- a/shaders/drawable.symbol_text_and_icon.fragment.glsl +++ b/shaders/drawable.symbol_text_and_icon.fragment.glsl @@ -3,28 +3,11 @@ #define SDF 1.0 #define ICON 0.0 -layout (std140) uniform SymbolDrawableUBO { - highp mat4 u_matrix; - highp mat4 u_label_plane_matrix; - highp mat4 u_coord_matrix; - - highp vec2 u_texsize; - highp vec2 u_texsize_icon; - - highp float u_gamma_scale; - bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - layout (std140) uniform SymbolTilePropsUBO { bool u_is_text; bool u_is_halo; - bool u_pitch_with_map; - bool u_is_size_zoom_constant; - bool u_is_size_feature_constant; - highp float u_size_t; // used to interpolate between zoom stops when size is a composite function - highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; + highp float u_gamma_scale; + lowp float tileprops_pad1; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -33,13 +16,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; uniform sampler2D u_texture; diff --git a/shaders/drawable.symbol_text_and_icon.vertex.glsl b/shaders/drawable.symbol_text_and_icon.vertex.glsl index d183ba43234..6035d451277 100644 --- a/shaders/drawable.symbol_text_and_icon.vertex.glsl +++ b/shaders/drawable.symbol_text_and_icon.vertex.glsl @@ -19,7 +19,8 @@ layout (std140) uniform GlobalPaintParamsUBO { highp float u_symbol_fade_change; highp float u_aspect_ratio; highp float u_pixel_ratio; - highp float global_pad1, global_pad2; + highp float u_map_zoom; + lowp float global_pad1; }; layout (std140) uniform SymbolDrawableUBO { @@ -30,29 +31,21 @@ layout (std140) uniform SymbolDrawableUBO { highp vec2 u_texsize; highp vec2 u_texsize_icon; - highp float u_gamma_scale; + bool u_is_text_prop; bool u_rotate_symbol; - highp vec2 drawable_pad1; -}; - -layout (std140) uniform SymbolTilePropsUBO { - bool u_is_text; - bool u_is_halo; bool u_pitch_with_map; bool u_is_size_zoom_constant; bool u_is_size_feature_constant; + highp float u_size_t; // used to interpolate between zoom stops when size is a composite function highp float u_size; // used when size is both zoom and feature constant - bool tileprops_pad1; -}; -layout (std140) uniform SymbolInterpolateUBO { + // Interpolations highp float u_fill_color_t; highp float u_halo_color_t; highp float u_opacity_t; highp float u_halo_width_t; highp float u_halo_blur_t; - highp float interp_pad1, interp_pad2, interp_pad3; }; layout (std140) uniform SymbolEvaluatedPropsUBO { @@ -61,13 +54,13 @@ layout (std140) uniform SymbolEvaluatedPropsUBO { highp float u_text_opacity; highp float u_text_halo_width; highp float u_text_halo_blur; - highp float props_pad1; + lowp float props_pad1; highp vec4 u_icon_fill_color; highp vec4 u_icon_halo_color; highp float u_icon_opacity; highp float u_icon_halo_width; highp float u_icon_halo_blur; - highp float props_pad2; + lowp float props_pad2; }; out vec4 v_data0; @@ -80,11 +73,11 @@ out vec4 v_data1; #pragma mapbox: define lowp float halo_blur void main() { - highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color; - highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color; - highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity; - highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width; - highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur; + highp vec4 u_fill_color = u_is_text_prop ? u_text_fill_color : u_icon_fill_color; + highp vec4 u_halo_color = u_is_text_prop ? u_text_halo_color : u_icon_halo_color; + highp float u_opacity = u_is_text_prop ? u_text_opacity : u_icon_opacity; + highp float u_halo_width = u_is_text_prop ? u_text_halo_width : u_icon_halo_width; + highp float u_halo_blur = u_is_text_prop ? u_text_halo_blur : u_icon_halo_blur; #pragma mapbox: initialize highp vec4 fill_color #pragma mapbox: initialize highp vec4 halo_color diff --git a/shaders/manifest.json b/shaders/manifest.json index 1c2f640ae69..049a3e4f31f 100644 --- a/shaders/manifest.json +++ b/shaders/manifest.json @@ -34,6 +34,13 @@ "glsl_frag": "drawable.collision_circle.fragment.glsl", "uses_ubos": true }, + { + "name": "CustomSymbolIconShader", + "header": "drawable_custom_symbol_icon", + "glsl_vert": "drawable.custom.symbol_icon.vertex.glsl", + "glsl_frag": "drawable.custom.symbol_icon.fragment.glsl", + "uses_ubos": true + }, { "name": "DebugShader", "header": "drawable_debug", @@ -139,6 +146,20 @@ "glsl_frag": "drawable.line_pattern.fragment.glsl", "uses_ubos": true }, + { + "name": "LocationIndicatorShader", + "header": "drawable_location_indicator", + "glsl_vert": "_empty.glsl", + "glsl_frag": "_empty.glsl", + "uses_ubos": true + }, + { + "name": "LocationIndicatorTexturedShader", + "header": "drawable_location_indicator_textured", + "glsl_vert": "_empty.glsl", + "glsl_frag": "_empty.glsl", + "uses_ubos": true + }, { "name": "LineSDFShader", "header": "drawable_line_sdf", @@ -174,19 +195,12 @@ "glsl_frag": "drawable.symbol_text_and_icon.fragment.glsl", "uses_ubos": true }, - { - "name": "CustomSymbolIconShader", - "header": "drawable_custom_symbol_icon", - "glsl_vert": "drawable.custom.symbol_icon.vertex.glsl", - "glsl_frag": "drawable.custom.symbol_icon.fragment.glsl", - "uses_ubos": true - }, { "name": "WideVectorShader", "header": "drawable_wide_vector", "glsl_vert": "_empty.glsl", "glsl_frag": "_empty.glsl", - "uses_ubos": false + "uses_ubos": true }, { diff --git a/src/mbgl/gfx/uniform_buffer.cpp b/src/mbgl/gfx/uniform_buffer.cpp index 5f357b99944..4ec8a2557d5 100644 --- a/src/mbgl/gfx/uniform_buffer.cpp +++ b/src/mbgl/gfx/uniform_buffer.cpp @@ -27,28 +27,37 @@ const std::shared_ptr& UniformBufferArray::get(const size_t id) c } const std::shared_ptr& UniformBufferArray::set(const size_t id, - std::shared_ptr uniformBuffer) { + std::shared_ptr uniformBuffer, + bool bindVertex, + bool bindFragment) { assert(id < uniformBufferVector.size()); if (id >= uniformBufferVector.size()) { return nullref; } uniformBufferVector[id] = std::move(uniformBuffer); + if (uniformBufferVector[id]) { + uniformBufferVector[id]->setBindVertex(bindVertex); + uniformBufferVector[id]->setBindFragment(bindFragment); + } return uniformBufferVector[id]; } void UniformBufferArray::createOrUpdate(const size_t id, const std::vector& data, gfx::Context& context, - bool persistent) { - createOrUpdate(id, data.data(), data.size(), context, persistent); + bool bindVertex, + bool bindFragment) { + createOrUpdate(id, data.data(), data.size(), context, bindVertex, bindFragment); } void UniformBufferArray::createOrUpdate( - const size_t id, const void* data, const std::size_t size, gfx::Context& context, bool persistent) { + const size_t id, const void* data, const std::size_t size, gfx::Context& context, bool bindVertex, bool bindFragment) { if (auto& ubo = get(id); ubo && ubo->getSize() == size) { ubo->update(data, size); } else { - uniformBufferVector[id] = context.createUniformBuffer(data, size, persistent); + uniformBufferVector[id] = context.createUniformBuffer(data, size, false); + uniformBufferVector[id]->setBindVertex(bindVertex); + uniformBufferVector[id]->setBindFragment(bindFragment); } } diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 03216eaa3d2..432592612a2 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -555,28 +555,13 @@ bool Context::emplaceOrUpdateUniformBuffer(gfx::UniformBufferPtr& buffer, void Context::bindGlobalUniformBuffers(gfx::RenderPass&) const noexcept { MLN_TRACE_FUNC(); - for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) { - const auto& globalUniformBuffer = globalUniformBuffers.get(id); - if (!globalUniformBuffer) continue; - GLint binding = static_cast(id); - const auto& uniformBufferGL = static_cast(*globalUniformBuffer); - MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER, - binding, - uniformBufferGL.getID(), - uniformBufferGL.getManagedBuffer().getBindingOffset(), - uniformBufferGL.getSize())); - } + globalUniformBuffers.bind(); } void Context::unbindGlobalUniformBuffers(gfx::RenderPass&) const noexcept { MLN_TRACE_FUNC(); - for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) { - const auto& globalUniformBuffer = globalUniformBuffers.get(id); - if (!globalUniformBuffer) continue; - GLint binding = static_cast(id); - MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0)); - } + globalUniformBuffers.unbind(); } #endif diff --git a/src/mbgl/gl/drawable_gl.cpp b/src/mbgl/gl/drawable_gl.cpp index 543196fcdf9..3a65cf4fb25 100644 --- a/src/mbgl/gl/drawable_gl.cpp +++ b/src/mbgl/gl/drawable_gl.cpp @@ -60,7 +60,7 @@ void DrawableGL::draw(PaintParameters& parameters) const { context.setColorMode(getColorMode()); context.setCullFaceMode(getCullFaceMode()); - bindUniformBuffers(); + impl->uniformBuffers.bind(); bindTextures(); for (const auto& seg : impl->segments) { @@ -76,7 +76,7 @@ void DrawableGL::draw(PaintParameters& parameters) const { #ifndef NDEBUG unbindTextures(); - unbindUniformBuffers(); + impl->uniformBuffers.unbind(); #endif } @@ -133,34 +133,6 @@ void DrawableGL::setVertexAttrId(const size_t id) { impl->vertexAttrId = id; } -void DrawableGL::bindUniformBuffers() const { - if (shader) { - const auto& uniformBlocks = shader->getUniformBlocks(); - for (size_t id = 0; id < uniformBlocks.allocatedSize(); id++) { - const auto& block = uniformBlocks.get(id); - if (!block) continue; - const auto& uniformBuffer = getUniformBuffers().get(id); - if (uniformBuffer) { - block->bindBuffer(*uniformBuffer); - } - } - } -} - -void DrawableGL::unbindUniformBuffers() const { - if (shader) { - const auto& uniformBlocks = shader->getUniformBlocks(); - for (size_t id = 0; id < uniformBlocks.allocatedSize(); id++) { - const auto& block = uniformBlocks.get(id); - if (!block) continue; - const auto& uniformBuffer = getUniformBuffers().get(id); - if (uniformBuffer) { - block->unbindBuffer(); - } - } - } -} - struct IndexBufferGL : public gfx::IndexBufferBase { IndexBufferGL(std::unique_ptr&& buffer_) : buffer(std::move(buffer_)) {} diff --git a/src/mbgl/gl/layer_group_gl.cpp b/src/mbgl/gl/layer_group_gl.cpp index 9e4ada2ec66..7f931d8a1c3 100644 --- a/src/mbgl/gl/layer_group_gl.cpp +++ b/src/mbgl/gl/layer_group_gl.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -128,7 +127,7 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) } if (!bindUBOs) { - bindUniformBuffers(); + uniformBuffers.bind(); bindUBOs = true; } @@ -136,31 +135,7 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) }); if (bindUBOs) { - unbindUniformBuffers(); - } -} - -void TileLayerGroupGL::bindUniformBuffers() const { - for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { - const auto& uniformBuffer = uniformBuffers.get(id); - if (!uniformBuffer) continue; - GLint binding = static_cast(id); - const auto& uniformBufferGL = static_cast(*uniformBuffer); - MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER, - binding, - uniformBufferGL.getID(), - uniformBufferGL.getManagedBuffer().getBindingOffset(), - uniformBufferGL.getSize())); - } -} - -void TileLayerGroupGL::unbindUniformBuffers() const { - MLN_TRACE_FUNC(); - for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { - const auto& uniformBuffer = uniformBuffers.get(id); - if (!uniformBuffer) continue; - GLint binding = static_cast(id); - MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0)); + uniformBuffers.unbind(); } } @@ -207,7 +182,7 @@ void LayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) { } if (!bindUBOs) { - bindUniformBuffers(); + uniformBuffers.bind(); bindUBOs = true; } @@ -215,30 +190,7 @@ void LayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) { }); if (bindUBOs) { - unbindUniformBuffers(); - } -} - -void LayerGroupGL::bindUniformBuffers() const { - for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { - const auto& uniformBuffer = uniformBuffers.get(id); - if (!uniformBuffer) continue; - GLint binding = static_cast(id); - const auto& uniformBufferGL = static_cast(*uniformBuffer); - MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER, - binding, - uniformBufferGL.getID(), - uniformBufferGL.getManagedBuffer().getBindingOffset(), - uniformBufferGL.getSize())); - } -} - -void LayerGroupGL::unbindUniformBuffers() const { - for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { - const auto& uniformBuffer = uniformBuffers.get(id); - if (!uniformBuffer) continue; - GLint binding = static_cast(id); - MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0)); + uniformBuffers.unbind(); } } diff --git a/src/mbgl/gl/uniform_buffer_gl.cpp b/src/mbgl/gl/uniform_buffer_gl.cpp index e678976d3ba..dd60a3b8e8d 100644 --- a/src/mbgl/gl/uniform_buffer_gl.cpp +++ b/src/mbgl/gl/uniform_buffer_gl.cpp @@ -125,5 +125,32 @@ void UniformBufferGL::update(const void* data_, std::size_t size_) { } } +void UniformBufferArrayGL::bind() const { + MLN_TRACE_FUNC(); + + for (size_t id = 0; id < allocatedSize(); id++) { + const auto& uniformBuffer = get(id); + if (!uniformBuffer) continue; + GLint binding = static_cast(id); + const auto& uniformBufferGL = static_cast(*uniformBuffer); + MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER, + binding, + uniformBufferGL.getID(), + uniformBufferGL.getManagedBuffer().getBindingOffset(), + uniformBufferGL.getSize())); + } +} + +void UniformBufferArrayGL::unbind() const { + MLN_TRACE_FUNC(); + + for (size_t id = 0; id < allocatedSize(); id++) { + const auto& uniformBuffer = get(id); + if (!uniformBuffer) continue; + GLint binding = static_cast(id); + MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0)); + } +} + } // namespace gl } // namespace mbgl diff --git a/src/mbgl/mtl/context.cpp b/src/mbgl/mtl/context.cpp index 60a0351624c..fddee302542 100644 --- a/src/mbgl/mtl/context.cpp +++ b/src/mbgl/mtl/context.cpp @@ -57,7 +57,7 @@ Context::~Context() noexcept { stencilStateRenderable = nullptr; for (size_t i = 0; i < globalUniformBuffers.allocatedSize(); i++) { - globalUniformBuffers.set(i, nullptr); + globalUniformBuffers.set(i, nullptr, false, false); } #if !defined(NDEBUG) @@ -199,7 +199,9 @@ gfx::UniqueDrawableBuilder Context::createDrawableBuilder(std::string name) { return std::make_unique(std::move(name)); } -gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool persistent) { +gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, + std::size_t size, + bool persistent) { return std::make_shared( createBuffer(data, size, gfx::BufferUsageType::StaticDraw, /*isIndexBuffer=*/false, persistent)); } @@ -415,7 +417,7 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass, // Adding a `[[depth(...)]]` output to the shader prevents this error, but the stencil value is // still not written to the stencil attachment on those same devices. #if STENCIL_INSTANCING - encoder->setVertexBuffer(uboBuffer.getMetalBuffer().get(), /*offset=*/0, ShaderClass::uniforms[0].index); + encoder->setVertexBuffer(uboBuffer.getMetalBuffer().get(), /*offset=*/0, shaders::idClippingMaskUBO); encoder->drawIndexedPrimitives(MTL::PrimitiveType::PrimitiveTypeTriangle, indexCount, MTL::IndexType::IndexTypeUInt16, @@ -423,10 +425,9 @@ bool Context::renderTileClippingMasks(gfx::RenderPass& renderPass, /*indexOffset=*/0, /*instanceCount=*/static_cast(tileUBOs.size())); #else - const auto uboIndex = ShaderClass::uniforms[0].index; for (std::size_t ii = 0; ii < tileUBOs.size(); ++ii) { encoder->setStencilReferenceValue(tileUBOs[ii].stencil_ref); - mtlRenderPass.bindVertex(*uboBuffer, /*offset=*/ii * uboSize, uboIndex, /*size=*/uboSize); + mtlRenderPass.bindVertex(*uboBuffer, /*offset=*/ii * uboSize, shaders::idClippingMaskUBO, /*size=*/uboSize); encoder->drawIndexedPrimitives(MTL::PrimitiveType::PrimitiveTypeTriangle, indexCount, MTL::IndexType::IndexTypeUInt16, @@ -626,15 +627,8 @@ MTLDepthStencilStatePtr Context::makeDepthStencilState(const gfx::DepthMode& dep } void Context::bindGlobalUniformBuffers(gfx::RenderPass& renderPass) const noexcept { - for (size_t id = 0; id < globalUniformBuffers.allocatedSize(); id++) { - const auto& globalUniformBuffer = globalUniformBuffers.get(id); - if (!globalUniformBuffer) continue; - const auto& buffer = static_cast(*globalUniformBuffer.get()); - const auto& resource = buffer.getBufferResource(); - auto& mtlRenderPass = static_cast(renderPass); - mtlRenderPass.bindVertex(resource, 0, id); - mtlRenderPass.bindFragment(resource, 0, id); - } + auto& mtlRenderPass = static_cast(renderPass); + globalUniformBuffers.bind(mtlRenderPass); } } // namespace mtl diff --git a/src/mbgl/mtl/drawable.cpp b/src/mbgl/mtl/drawable.cpp index ce8a7d800cd..3746f039b13 100644 --- a/src/mbgl/mtl/drawable.cpp +++ b/src/mbgl/mtl/drawable.cpp @@ -186,10 +186,15 @@ void Drawable::draw(PaintParameters& parameters) const { const auto debugGroup = parameters.encoder->createDebugGroup(debugLabel(*this)); #endif + renderPass.unbindVertex(shaders::idGlobalUBOIndex); + renderPass.unbindFragment(shaders::idGlobalUBOIndex); + encoder->setVertexBytes(&uboIndex, sizeof(uboIndex), shaders::idGlobalUBOIndex); + encoder->setFragmentBytes(&uboIndex, sizeof(uboIndex), shaders::idGlobalUBOIndex); + bindAttributes(renderPass); bindInstanceAttributes(renderPass); - bindUniformBuffers(renderPass); bindTextures(renderPass); + impl->uniformBuffers.bind(renderPass); if (!impl->indexes->getBuffer() || impl->indexes->getDirty()) { assert(!"Index buffer not uploaded"); @@ -310,8 +315,8 @@ void Drawable::draw(PaintParameters& parameters) const { } } + impl->uniformBuffers.unbind(renderPass); unbindTextures(renderPass); - unbindUniformBuffers(renderPass); unbindAttributes(renderPass); } @@ -411,29 +416,6 @@ void Drawable::bindInstanceAttributes(RenderPass& renderPass) const noexcept { } } -void Drawable::bindUniformBuffers(RenderPass& renderPass) const noexcept { - if (shader) { - const auto& uniformBlocks = shader->getUniformBlocks(); - for (size_t id = 0; id < uniformBlocks.allocatedSize(); id++) { - const auto& block = uniformBlocks.get(id); - if (!block) continue; - const auto& uniformBuffer = getUniformBuffers().get(id); - if (uniformBuffer) { - const auto& buffer = static_cast(*uniformBuffer.get()); - const auto& resource = buffer.getBufferResource(); - const auto& mtlBlock = static_cast(*block); - - if (mtlBlock.getBindVertex()) { - renderPass.bindVertex(resource, /*offset=*/0, block->getIndex()); - } - if (mtlBlock.getBindFragment()) { - renderPass.bindFragment(resource, /*offset=*/0, block->getIndex()); - } - } - } - } -} - void Drawable::bindTextures(RenderPass& renderPass) const noexcept { for (size_t id = 0; id < textures.size(); id++) { if (const auto& texture = textures[id]) { diff --git a/src/mbgl/mtl/layer_group.cpp b/src/mbgl/mtl/layer_group.cpp index c653334bd28..406624e685e 100644 --- a/src/mbgl/mtl/layer_group.cpp +++ b/src/mbgl/mtl/layer_group.cpp @@ -57,7 +57,7 @@ void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { } if (!bindUBOs) { - bindUniformBuffers(renderPass); + uniformBuffers.bind(renderPass); bindUBOs = true; } @@ -65,18 +65,7 @@ void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { }); if (bindUBOs) { - unbindUniformBuffers(renderPass); - } -} - -void LayerGroup::bindUniformBuffers(RenderPass& renderPass) const noexcept { - for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { - const auto& uniformBuffer = uniformBuffers.get(id); - if (!uniformBuffer) continue; - const auto& buffer = static_cast(*uniformBuffer.get()); - const auto& resource = buffer.getBufferResource(); - renderPass.bindVertex(resource, 0, id); - renderPass.bindFragment(resource, 0, id); + uniformBuffers.unbind(renderPass); } } diff --git a/src/mbgl/mtl/render_pass.cpp b/src/mbgl/mtl/render_pass.cpp index 2ffee68c4d6..c5ade2802e5 100644 --- a/src/mbgl/mtl/render_pass.cpp +++ b/src/mbgl/mtl/render_pass.cpp @@ -122,6 +122,10 @@ void RenderPass::bindVertex(const BufferResource& buf, std::size_t offset, std:: buf.bindVertex(encoder, offset, index, actualSize); } +void RenderPass::unbindVertex(std::size_t index) { + vertexBinds[index] = std::nullopt; +} + void RenderPass::bindFragment(const BufferResource& buf, std::size_t offset, std::size_t index, std::size_t size) { const auto actualSize = size ? size : buf.getSizeInBytes() - offset; assert(actualSize <= buf.getSizeInBytes()); @@ -144,6 +148,10 @@ void RenderPass::bindFragment(const BufferResource& buf, std::size_t offset, std buf.bindFragment(encoder, offset, index, actualSize); } +void RenderPass::unbindFragment(std::size_t index) { + fragmentBinds[index] = std::nullopt; +} + void RenderPass::setDepthStencilState(const MTLDepthStencilStatePtr& state) { if (state != currentDepthStencilState) { currentDepthStencilState = state; diff --git a/src/mbgl/mtl/renderer_backend.cpp b/src/mbgl/mtl/renderer_backend.cpp index dbeba967412..6e8748e912a 100644 --- a/src/mbgl/mtl/renderer_backend.cpp +++ b/src/mbgl/mtl/renderer_backend.cpp @@ -12,26 +12,20 @@ // ... shader_manifest.hpp #include -#include #include #include -#include -#include +#include #include #include #include #include -#include #include #include #include #include #include -#include #include -#include -#include -#include +#include #include #include diff --git a/src/mbgl/mtl/tile_layer_group.cpp b/src/mbgl/mtl/tile_layer_group.cpp index 0a8202415b2..2993a919ba2 100644 --- a/src/mbgl/mtl/tile_layer_group.cpp +++ b/src/mbgl/mtl/tile_layer_group.cpp @@ -139,7 +139,7 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { } if (!bindUBOs) { - bindUniformBuffers(renderPass); + uniformBuffers.bind(renderPass); bindUBOs = true; } @@ -147,18 +147,7 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) { }); if (bindUBOs) { - unbindUniformBuffers(renderPass); - } -} - -void TileLayerGroup::bindUniformBuffers(RenderPass& renderPass) const noexcept { - for (size_t id = 0; id < uniformBuffers.allocatedSize(); id++) { - const auto& uniformBuffer = uniformBuffers.get(id); - if (!uniformBuffer) continue; - const auto& buffer = static_cast(*uniformBuffer.get()); - const auto& resource = buffer.getBufferResource(); - renderPass.bindVertex(resource, 0, id); - renderPass.bindFragment(resource, 0, id); + uniformBuffers.unbind(renderPass); } } diff --git a/src/mbgl/mtl/uniform_buffer.cpp b/src/mbgl/mtl/uniform_buffer.cpp index 57107870f84..1b346f33823 100644 --- a/src/mbgl/mtl/uniform_buffer.cpp +++ b/src/mbgl/mtl/uniform_buffer.cpp @@ -1,5 +1,5 @@ #include - +#include #include #include @@ -25,17 +25,32 @@ UniformBuffer::~UniformBuffer() { } void UniformBuffer::update(const void* data, std::size_t size_) { - assert(size == size_); + /*assert(size == size_); if (size != size_ || size != buffer.getSizeInBytes()) { Log::Error( Event::General, "Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_)); return; - } + }*/ buffer.getContext().renderingStats().numUniformUpdates++; buffer.getContext().renderingStats().uniformUpdateBytes += size_; - buffer.update(data, size, /*offset=*/0); + buffer.update(data, size_, /*offset=*/0); +} + +void UniformBufferArray::bind(RenderPass& renderPass) const noexcept { + for (size_t id = 0; id < allocatedSize(); id++) { + const auto& uniformBuffer = get(id); + if (!uniformBuffer) continue; + const auto& buffer = static_cast(*uniformBuffer.get()); + const auto& resource = buffer.getBufferResource(); + if (buffer.getBindVertex()) { + renderPass.bindVertex(resource, 0, id); + } + if (buffer.getBindFragment()) { + renderPass.bindFragment(resource, 0, id); + } + } } } // namespace mtl diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index 029ebec25e1..4552977ba33 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -53,26 +53,35 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara auto& layerUniforms = layerGroup.mutableUniformBuffers(); if (hasPattern) { - const BackgroundPatternLayerUBO layerUBO = {/* .pattern_tl_a = */ util::cast(imagePosA->tl()), - /* .pattern_br_a = */ util::cast(imagePosA->br()), - /* .pattern_tl_b = */ util::cast(imagePosB->tl()), - /* .pattern_br_b = */ util::cast(imagePosB->br()), - /* .pattern_size_a = */ imagePosA->displaySize(), - /* .pattern_size_b = */ imagePosB->displaySize(), - /* .scale_a = */ crossfade.fromScale, - /* .scale_b = */ crossfade.toScale, - /* .mix = */ crossfade.t, - /* .opacity = */ evaluated.get()}; - layerUniforms.createOrUpdate(idBackgroundLayerUBO, &layerUBO, context); + const BackgroundPatternPropsUBO propsUBO = { + /* .pattern_tl_a = */ util::cast(imagePosA->tl()), + /* .pattern_br_a = */ util::cast(imagePosA->br()), + /* .pattern_tl_b = */ util::cast(imagePosB->tl()), + /* .pattern_br_b = */ util::cast(imagePosB->br()), + /* .pattern_size_a = */ imagePosA->displaySize(), + /* .pattern_size_b = */ imagePosB->displaySize(), + /* .scale_a = */ crossfade.fromScale, + /* .scale_b = */ crossfade.toScale, + /* .mix = */ crossfade.t, + /* .opacity = */ evaluated.get() + }; + layerUniforms.createOrUpdate(idBackgroundPropsUBO, &propsUBO, context, true, true); } else { - const BackgroundLayerUBO layerUBO = {/* .color = */ evaluated.get(), - /* .opacity = */ evaluated.get(), - /* .pad1/2/3 = */ 0, - 0, - 0}; - layerUniforms.createOrUpdate(idBackgroundLayerUBO, &layerUBO, context); + const BackgroundPropsUBO propsUBO = { + /* .color = */ evaluated.get(), + /* .opacity = */ evaluated.get(), + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; + layerUniforms.createOrUpdate(idBackgroundPropsUBO, &propsUBO, context, false, true); } +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { assert(drawable.getTileID()); if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -103,20 +112,51 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara const int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y; const auto pixToTile = tileID.pixelsToTileUnits(1.0f, state.getIntegerZoom()); +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].backgroundPatternDrawableUBO = { +#else const BackgroundPatternDrawableUBO drawableUBO = { +#endif /* .matrix = */ util::cast(matrix), /* .pixel_coord_upper = */ {static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, /* .pixel_coord_lower = */ {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /* .tile_units_to_pixels = */ (pixToTile != 0) ? 1.0f / pixToTile : 0.0f, - /* .pad1/2/3 = */ 0, - 0, - 0}; - drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context, true, false); +#endif } else { - const BackgroundDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix)}; - drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); + +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].backgroundDrawableUBO = { +#else + const BackgroundDrawableUBO drawableUBO = { +#endif + /* .matrix = */ util::cast(matrix) + }; +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context, true, false); +#endif } + +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#endif }); + +#if MLN_UBO_CONSOLIDATION + const size_t drawableUBOVectorSize = sizeof(BackgroundDrawableUnionUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + layerUniforms.set(idBackgroundDrawableUBO, drawableUniformBuffer, true, false); +#endif } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.hpp b/src/mbgl/renderer/layers/background_layer_tweaker.hpp index b696e3cd579..243c7a43d89 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.hpp @@ -26,6 +26,11 @@ class BackgroundLayerTweaker : public LayerTweaker { ~BackgroundLayerTweaker() override = default; void execute(LayerGroupBase&, const PaintParameters&) override; + +protected: +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; +#endif }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index 21348ae1619..a4f33675aff 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -56,8 +56,13 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer); + layerUniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { assert(drawable.getTileID() || !"Circles only render with tiles"); if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -82,28 +87,44 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete const auto extrudeScale = pitchWithMap ? std::array{pixelsToTileUnits, pixelsToTileUnits} : parameters.pixelsToGLUnits; - // Updated for each drawable on each frame - const CircleDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix), - /* .extrude_scale = */ extrudeScale, - /* .padding = */ 0}; - - auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context); +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i] = { +#else + const CircleDrawableUBO drawableUBO = { +#endif + + /* .matrix = */ util::cast(matrix), + /* .extrude_scale = */ extrudeScale, - const CircleInterpolateUBO interpolateUBO = { /* .color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .radius_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .blur_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .stroke_color_t = */ - std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .stroke_width_t = */ - std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .stroke_opacity_t = */ - std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .padding = */ 0}; - drawableUniforms.createOrUpdate(idCircleInterpolateUBO, &interpolateUBO, context); + /* .stroke_color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .stroke_width_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .stroke_opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#else + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context, true, false); +#endif }); + +#if MLN_UBO_CONSOLIDATION + const size_t drawableUBOVectorSize = sizeof(CircleDrawableUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + layerUniforms.set(idCircleDrawableUBO, drawableUniformBuffer, true, false); +#endif } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.hpp b/src/mbgl/renderer/layers/circle_layer_tweaker.hpp index 30a3e7ee125..70208e0f324 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.hpp @@ -20,6 +20,10 @@ class CircleLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; + +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; +#endif }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp index 0f3eb8086c4..4b0fa93fe84 100644 --- a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp @@ -58,14 +58,19 @@ void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const std::array extrudeScale = {{parameters.pixelsToGLUnits[0] / (pixelRatio * scale), parameters.pixelsToGLUnits[1] / (pixelRatio * scale)}}; - const CollisionUBO drawableUBO = { - /*.matrix=*/util::cast(matrix), - /*.extrude_scale*/ extrudeScale, - /*.overscale_factor*/ static_cast(drawable.getTileID()->overscaleFactor()), - /*.pad*/ 0}; + const CollisionDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(matrix) + }; + + const CollisionTilePropsUBO tilePropsUBO = { + /* .extrude_scale = */ extrudeScale, + /* .overscale_factor = */ static_cast(drawable.getTileID()->overscaleFactor()), + /* .pad1 = */ 0 + }; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idCollisionUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idCollisionDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idCollisionTilePropsUBO, &tilePropsUBO, context, true, true); }); } diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index 24057479af8..9f6591308ad 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -16,7 +16,6 @@ #if MLN_RENDER_BACKEND_METAL #include -#include #endif namespace mbgl { @@ -57,7 +56,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP /* .to_scale = */ crossfade.toScale, /* .pad = */ 0}; auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idFillExtrusionPropsUBO, &propsUBO, context); + layerUniforms.createOrUpdate(idFillExtrusionPropsUBO, &propsUBO, context, true, true); propertiesUpdated = false; @@ -65,6 +64,12 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP const auto defPattern = mbgl::Faded{"", ""}; const auto fillPatternValue = evaluated.get().constantOr(defPattern); +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); + std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { return; @@ -107,34 +112,64 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP binders->setPatternParameters(patternPosA, patternPosB, crossfade); } +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i] = { +#else const FillExtrusionDrawableUBO drawableUBO = { +#endif /* .matrix = */ util::cast(matrix), - /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, /* .pixel_coord_upper = */ {static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, /* .pixel_coord_lower = */ {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /* .height_factor = */ heightFactor, - /* .tile_ratio = */ tileRatio}; + /* .tile_ratio = */ tileRatio, - const FillExtrusionInterpolateUBO interpUBO = { /* .base_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .height_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .pattern_from_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .pattern_to_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .pad = */ 0, - 0, - 0}; + /* .pad1 = */ 0 + }; +#if MLN_UBO_CONSOLIDATION + tilePropsUBOVector[i] = { +#else const FillExtrusionTilePropsUBO tilePropsUBO = { +#endif /* pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, /* pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context); - drawableUniforms.createOrUpdate(idFillExtrusionTilePropsUBO, &tilePropsUBO, context); - drawableUniforms.createOrUpdate(idFillExtrusionInterpolateUBO, &interpUBO, context); + drawableUniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idFillExtrusionTilePropsUBO, &tilePropsUBO, context, true, true); +#endif }); + +#if MLN_UBO_CONSOLIDATION + const size_t drawableUBOVectorSize = sizeof(FillExtrusionDrawableUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + const size_t tilePropsUBOVectorSize = sizeof(FillExtrusionTilePropsUBO) * tilePropsUBOVector.size(); + if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + } else { + tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); + } + + layerUniforms.set(idFillExtrusionDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idFillExtrusionTilePropsUBO, tilePropsUniformBuffer, true, true); +#endif } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp index 7bc7a2d1bf4..8a0393553f4 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp @@ -19,8 +19,13 @@ class FillExtrusionLayerTweaker : public LayerTweaker { void execute(LayerGroupBase&, const PaintParameters&) override; -private: +protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; + +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; + gfx::UniformBufferPtr tilePropsUniformBuffer; +#endif }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 352f32cb879..924406473ac 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -50,13 +50,19 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idFillEvaluatedPropsUBO, evaluatedPropsUniformBuffer); + layerUniforms.set(idFillEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); const auto& translation = evaluated.get(); const auto anchor = evaluated.get(); const auto zoom = static_cast(parameters.state.getZoom()); const auto intZoom = parameters.state.getIntegerZoom(); +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); + std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { return; @@ -99,90 +105,127 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters switch (static_cast(drawable.getType())) { case RenderFillLayer::FillVariant::Fill: { - const FillDrawableUBO drawableUBO = {/*.matrix=*/util::cast(matrix)}; - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); - - const auto fillInterpolateUBO = FillInterpolateUBO{ +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].fillDrawableUBO = { +#else + const FillDrawableUBO drawableUBO = { +#endif + /* .matrix = */ util::cast(matrix), + /* .color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - 0, - 0, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; - drawableUniforms.createOrUpdate(idFillInterpolateUBO, &fillInterpolateUBO, context); + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); +#endif break; } case RenderFillLayer::FillVariant::FillOutline: { - const FillOutlineDrawableUBO drawableUBO = {/*.matrix=*/util::cast(matrix)}; - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); - - const auto fillOutlineInterpolateUBO = FillOutlineInterpolateUBO{ - /* .color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].fillOutlineDrawableUBO = { +#else + const FillOutlineDrawableUBO drawableUBO = { +#endif + /* .matrix=*/util::cast(matrix), + + /* .outline_color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - 0, - 0, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; - drawableUniforms.createOrUpdate(idFillInterpolateUBO, &fillOutlineInterpolateUBO, context); + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); +#endif break; } case RenderFillLayer::FillVariant::FillPattern: { +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].fillPatternDrawableUBO = { +#else const FillPatternDrawableUBO drawableUBO = { - /*.matrix=*/util::cast(matrix), - /*.pixel_coord_upper=*/{static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, - /*.pixel_coord_lower=*/{static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, - /*.texsize=*/{static_cast(textureSize.width), static_cast(textureSize.height)}, - /*.tile_ratio = */ tileRatio, - 0, - }; - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); +#endif + /* .matrix = */ util::cast(matrix), + /* .pixel_coord_upper = */ {static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, + /* .pixel_coord_lower = */ {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, + /* .tile_ratio = */ tileRatio, - const auto fillPatternInterpolateUBO = FillPatternInterpolateUBO{ /* .pattern_from_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .pattern_to_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - 0, + /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)) }; - drawableUniforms.createOrUpdate(idFillInterpolateUBO, &fillPatternInterpolateUBO, context); - const auto fillPatternTilePropsUBO = FillPatternTilePropsUBO{ - /* pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, - /* pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, +#if MLN_UBO_CONSOLIDATION + tilePropsUBOVector[i].fillPatternTilePropsUBO = FillPatternTilePropsUBO { +#else + const FillPatternTilePropsUBO tilePropsUBO = { +#endif + /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, + /* .pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; - drawableUniforms.createOrUpdate(idFillTilePropsUBO, &fillPatternTilePropsUBO, context); + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idFillTilePropsUBO, &tilePropsUBO, context, true, true); +#endif break; } case RenderFillLayer::FillVariant::FillOutlinePattern: { +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].fillOutlinePatternDrawableUBO = { +#else const FillOutlinePatternDrawableUBO drawableUBO = { - /*.matrix=*/util::cast(matrix), - /*.pixel_coord_upper=*/{static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, - /*.pixel_coord_lower=*/{static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, - /*.texsize=*/{static_cast(textureSize.width), static_cast(textureSize.height)}, - /*.tile_ratio = */ tileRatio, - 0}; - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); - - const auto fillOutlinePatternInterpolateUBO = FillPatternInterpolateUBO{ +#endif + /* .matrix = */ util::cast(matrix), + /* .pixel_coord_upper = */ {static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, + /* .pixel_coord_lower = */ {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, + /* .tile_ratio = */ tileRatio, + /* .pattern_from_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .pattern_to_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - 0, + /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)) }; - drawableUniforms.createOrUpdate(idFillInterpolateUBO, &fillOutlinePatternInterpolateUBO, context); - const auto fillOutlinePatternTilePropsUBO = FillOutlinePatternTilePropsUBO{ - /* pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, - /* pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, +#if MLN_UBO_CONSOLIDATION + tilePropsUBOVector[i].fillOutlinePatternTilePropsUBO = FillOutlinePatternTilePropsUBO { +#else + const FillOutlinePatternTilePropsUBO tilePropsUBO = { +#endif + /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, + /* .pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; - drawableUniforms.createOrUpdate(idFillTilePropsUBO, &fillOutlinePatternTilePropsUBO, context); + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idFillTilePropsUBO, &tilePropsUBO, context, true, true); +#endif break; } case RenderFillLayer::FillVariant::FillOutlineTriangulated: { +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].fillOutlineTriangulatedDrawableUBO = { +#else const FillOutlineTriangulatedDrawableUBO drawableUBO = { - /*.matrix=*/util::cast(matrix), - /*.ratio=*/1.0f / tileID.pixelsToTileUnits(1.0f, parameters.state.getZoom()), - 0, - 0, - 0}; - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); +#endif + /* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, parameters.state.getZoom()), + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); +#endif break; } default: { @@ -192,7 +235,29 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters break; } } +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#endif }); + +#if MLN_UBO_CONSOLIDATION + const size_t drawableUBOVectorSize = sizeof(FillDrawableUnionUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + const size_t tilePropsUBOVectorSize = sizeof(FillTilePropsUnionUBO) * tilePropsUBOVector.size(); + if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + } else { + tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); + } + + layerUniforms.set(idFillDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idFillTilePropsUBO, tilePropsUniformBuffer, true, true); +#endif } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.hpp b/src/mbgl/renderer/layers/fill_layer_tweaker.hpp index dc67bc4dd40..7505e49c4b0 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.hpp @@ -21,6 +21,11 @@ class FillLayerTweaker : public LayerTweaker { private: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; + +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; + gfx::UniformBufferPtr tilePropsUniformBuffer; +#endif }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index 348a998c90a..7809a55c064 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -44,8 +44,13 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idHeatmapEvaluatedPropsUBO, evaluatedPropsUniformBuffer); + layerUniforms.set(idHeatmapEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { return; @@ -64,19 +69,37 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet constexpr bool inViewportPixelUnits = false; const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, nearClipped, inViewportPixelUnits, drawable); - const HeatmapDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix), - /* .extrude_scale = */ tileID.pixelsToTileUnits(1.0f, zoom), - /* .padding = */ {0}}; - - auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context); + +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i] = { +#else + const HeatmapDrawableUBO drawableUBO = { +#endif + /* .matrix = */ util::cast(matrix), + /* .extrude_scale = */ tileID.pixelsToTileUnits(1.0f, zoom), - const HeatmapInterpolateUBO interpolateUBO = { /* .weight_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .radius_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .padding = */ {0}}; - drawableUniforms.createOrUpdate(idHeatmapInterpolateUBO, &interpolateUBO, context); + /* .pad1 = */ 0 + }; +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#else + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context, true, false); +#endif }); + +#if MLN_UBO_CONSOLIDATION + const size_t drawableUBOVectorSize = sizeof(HeatmapDrawableUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + layerUniforms.set(idSymbolDrawableUBO, drawableUniformBuffer, true, false); +#endif } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp index 3cd17b31e82..d42cf1d0785 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp @@ -19,6 +19,10 @@ class HeatmapLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; + +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; +#endif }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index 635103c178a..8c849d4532e 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -33,13 +33,15 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint const auto& size = parameters.staticData.backendSize; matrix::ortho(matrix, 0, size.width, size.height, 0, -1, 1); - const HeatmapTexturePropsUBO propsUBO = {/* .matrix = */ util::cast(matrix), - /* .opacity = */ evaluated.get(), - /* .pad1,2,3 = */ 0, - 0, - 0}; + const HeatmapTexturePropsUBO propsUBO = { + /* .matrix = */ util::cast(matrix), + /* .opacity = */ evaluated.get(), + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idHeatmapTexturePropsUBO, &propsUBO, parameters.context); + layerUniforms.createOrUpdate(idHeatmapTexturePropsUBO, &propsUBO, parameters.context, true, true); } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index 01d913b5e85..8a96082b48b 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -52,8 +52,14 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idHillshadeEvaluatedPropsUBO, evaluatedPropsUniformBuffer); + layerUniforms.set(idHillshadeEvaluatedPropsUBO, evaluatedPropsUniformBuffer, false, true); +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); + std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { return; @@ -63,12 +69,52 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, false, false, drawable, true); - HillshadeDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix), - /* .latrange = */ getLatRange(tileID), - /* .light = */ getLight(parameters, evaluated)}; + +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i] = { +#else + const HillshadeDrawableUBO drawableUBO = { +#endif + /* .matrix = */ util::cast(matrix) + }; + +#if MLN_UBO_CONSOLIDATION + tilePropsUBOVector[i] = { +#else + const HillshadeTilePropsUBO tilePropsUBO = { +#endif + /* .latrange = */ getLatRange(tileID), + /* .light = */ getLight(parameters, evaluated) + }; + +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idHillshadeDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idHillshadeDrawableUBO, &drawableUBO, parameters.context, true, false); + drawableUniforms.createOrUpdate(idHillshadeTilePropsUBO, &tilePropsUBO, parameters.context, false, true); +#endif }); + +#if MLN_UBO_CONSOLIDATION + auto& context = parameters.context; + const size_t drawableUBOVectorSize = sizeof(HillshadeDrawableUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + const size_t tilePropsUBOVectorSize = sizeof(HillshadeTilePropsUBO) * tilePropsUBOVector.size(); + if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + } else { + tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); + } + + layerUniforms.set(idHillshadeDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idHillshadeTilePropsUBO, tilePropsUniformBuffer, false, true); +#endif } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.hpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.hpp index 3c7d1016663..8efdbfbef23 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.hpp @@ -19,6 +19,11 @@ class HillshadeLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; + +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; + gfx::UniformBufferPtr tilePropsUniformBuffer; +#endif }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp index 2b4ddf8dd1a..e28693fefdb 100644 --- a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp @@ -51,14 +51,18 @@ void HillshadePrepareLayerTweaker::execute(LayerGroupBase& layerGroup, const Pai matrix::translate(matrix, matrix, 0, -util::EXTENT, 0); const HillshadePrepareDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(matrix), + /* .matrix = */ util::cast(matrix) + }; + const HillshadePrepareTilePropsUBO tilePropsUBO = { /* .unpack = */ getUnpackVector(drawableData.encoding), /* .dimension = */ {static_cast(drawableData.stride), static_cast(drawableData.stride)}, /* .zoom = */ static_cast(tileID.canonical.z), - /* .maxzoom = */ static_cast(drawableData.maxzoom)}; + /* .maxzoom = */ static_cast(drawableData.maxzoom) + }; - drawable.mutableUniformBuffers().createOrUpdate( - idHillshadePrepareDrawableUBO, &drawableUBO, parameters.context); + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idHillshadePrepareDrawableUBO, &drawableUBO, parameters.context, true, false); + drawableUniforms.createOrUpdate(idHillshadePrepareTilePropsUBO, &tilePropsUBO, parameters.context, true, true); }); } diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index a90b4c6af1d..6dad4693880 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -148,14 +148,19 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - - layerUniforms.set(idLineEvaluatedPropsUBO, evaluatedPropsUniformBuffer); + layerUniforms.set(idLineEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); #if MLN_RENDER_BACKEND_METAL // GPU Expressions - layerUniforms.set(idLineExpressionUBO, getExpressionBuffer()); + layerUniforms.set(idLineExpressionUBO, getExpressionBuffer(), true, true); #endif // MLN_RENDER_BACKEND_METAL +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); + std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { const auto shader = drawable.getShader(); if (!drawable.getTileID() || !shader || !checkTweakDrawable(drawable)) { @@ -185,45 +190,50 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters auto& drawableUniforms = drawable.mutableUniformBuffers(); switch (static_cast(drawable.getType())) { case LineType::Simple: { +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].lineDrawableUBO = { +#else const LineDrawableUBO drawableUBO = { - /*matrix = */ util::cast(matrix), - /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), - 0, - 0, - 0}; - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); - - const auto lineInterpolationUBO = LineInterpolationUBO{ - /*color_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*blur_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*opacity_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*gapwidth_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*offset_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*width_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - 0, - 0}; - drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, context); +#endif + /* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), + + /* .color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .blur_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .gapwidth_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .offset_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .width_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .pad1 = */ 0 + }; + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); +#endif + } break; case LineType::Gradient: { +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].lineGradientDrawableUBO = { +#else const LineGradientDrawableUBO drawableUBO = { - /*matrix = */ util::cast(matrix), - /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), - 0, - 0, - 0}; - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); - - const auto lineGradientInterpolationUBO = LineGradientInterpolationUBO{ - /*blur_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*opacity_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*gapwidth_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*offset_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*width_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - 0, - 0, - 0}; - drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineGradientInterpolationUBO, context); +#endif + /* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), + + /* .blur_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .gapwidth_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .offset_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .width_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .pad1 = */ 0, + /* .pad2 = */ 0 + }; + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); +#endif } break; case LineType::Pattern: { @@ -231,33 +241,40 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters if (const auto& texture = drawable.getTexture(idLineImageTexture)) { textureSize = texture->getSize(); } +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].linePatternDrawableUBO = { +#else const LinePatternDrawableUBO drawableUBO = { - /*matrix =*/util::cast(matrix), - /*scale =*/ - {parameters.pixelRatio, - 1 / tileID.pixelsToTileUnits(1, intZoom), - crossfade.fromScale, - crossfade.toScale}, - /*texsize =*/{static_cast(textureSize.width), static_cast(textureSize.height)}, - /*ratio =*/1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), - /*fade =*/crossfade.t}; - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); - - const auto linePatternInterpolationUBO = LinePatternInterpolationUBO{ - /*blur_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*opacity_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*offset_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*gapwidth_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*width_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*pattern_from_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*pattern_to_t =*/std::get<1>(binders->get()->interpolationFactor(zoom)), - 0}; - drawableUniforms.createOrUpdate(idLineInterpolationUBO, &linePatternInterpolationUBO, context); - - const auto linePatternTilePropertiesUBO = LinePatternTilePropertiesUBO{ - /*pattern_from =*/patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, - /*pattern_to =*/patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}}; - drawableUniforms.createOrUpdate(idLineTilePropertiesUBO, &linePatternTilePropertiesUBO, context); +#endif + /* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), + + /* .blur_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .offset_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .gapwidth_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .width_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .pattern_from_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .pattern_to_t = */ std::get<1>(binders->get()->interpolationFactor(zoom)) + }; + +#if MLN_UBO_CONSOLIDATION + tilePropsUBOVector[i].linePatternTilePropsUBO = LinePatternTilePropsUBO { +#else + const LinePatternTilePropsUBO tilePropsUBO = { +#endif + /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, + /* .pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + /* .scale = */ {parameters.pixelRatio, 1 / tileID.pixelsToTileUnits(1, intZoom), crossfade.fromScale, crossfade.toScale}, + /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, + /* .fade = */ crossfade.t, + /* .pad1 = */ 0 + }; + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idLineTilePropsUBO, &tilePropsUBO, context, false, true); +#endif } break; case LineType::SDF: { @@ -281,34 +298,46 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const LinePatternPos& posB = dashPatternTexture.getTo(); const float widthA = posA.width * crossfade.fromScale; const float widthB = posB.width * crossfade.toScale; - const LineSDFDrawableUBO drawableUBO{ - /* matrix = */ util::cast(matrix), - /* patternscale_a = */ - {1.0f / tileID.pixelsToTileUnits(widthA, intZoom), -posA.height / 2.0f}, - /* patternscale_b = */ - {1.0f / tileID.pixelsToTileUnits(widthB, intZoom), -posB.height / 2.0f}, - /* ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - /* tex_y_a = */ posA.y, - /* tex_y_b = */ posB.y, - /* sdfgamma = */ static_cast(dashPatternTexture.getSize().width) / - (std::min(widthA, widthB) * 256.0f * parameters.pixelRatio) / 2.0f, - /* mix = */ crossfade.t, - 0, - 0, - 0}; - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); - - const auto lineSDFInterpolationUBO = LineSDFInterpolationUBO{ - /*color_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*blur_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*opacity_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*gapwidth_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*offset_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*width_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /*floorwidth_t =*/ - std::get<0>(binders->get()->interpolationFactor(zoom)), - 0}; - drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineSDFInterpolationUBO, context); + +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].lineSDFDrawableUBO = { +#else + const LineSDFDrawableUBO drawableUBO = { +#endif + /* .matrix = */ util::cast(matrix), + /* .patternscale_a = */ {1.0f / tileID.pixelsToTileUnits(widthA, intZoom), -posA.height / 2.0f}, + /* .patternscale_b = */ {1.0f / tileID.pixelsToTileUnits(widthB, intZoom), -posB.height / 2.0f}, + /* .tex_y_a = */ posA.y, + /* .tex_y_b = */ posB.y, + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), + + /* .color_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .blur_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .opacity_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .gapwidth_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .offset_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .width_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .floorwidth_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .pad1 = */ 0, + /* .pad2 = */ 0 + }; + +#if MLN_UBO_CONSOLIDATION + tilePropsUBOVector[i].lineSDFTilePropsUBO = LineSDFTilePropsUBO { +#else + const LineSDFTilePropsUBO tilePropsUBO = { +#endif + + /* .sdfgamma = */ static_cast(dashPatternTexture.getSize().width) / (std::min(widthA, widthB) * 256.0f * parameters.pixelRatio) / 2.0f, + /* .mix = */ crossfade.t, + /* .pad1 = */ 0, + /* .pad2 = */ 0 + }; + +#if !MLN_UBO_CONSOLIDATION + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idLineTilePropsUBO, &tilePropsUBO, context, false, true); +#endif } } break; @@ -317,7 +346,30 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters "LineLayerTweaker: unknown line type: " + std::to_string(drawable.getType())); } break; } + +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#endif }); + +#if MLN_UBO_CONSOLIDATION + const size_t drawableUBOVectorSize = sizeof(LineDrawableUnionUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + const size_t tilePropsUBOVectorSize = sizeof(LineTilePropsUnionUBO) * tilePropsUBOVector.size(); + if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + } else { + tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); + } + + layerUniforms.set(idLineDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idLineTilePropsUBO, tilePropsUniformBuffer, false, true); +#endif } #if MLN_RENDER_BACKEND_METAL diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.hpp b/src/mbgl/renderer/layers/line_layer_tweaker.hpp index 3295816fe2a..0e27327fb73 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.hpp @@ -60,6 +60,11 @@ class LineLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; + gfx::UniformBufferPtr tilePropsUniformBuffer; +#endif + #if MLN_RENDER_BACKEND_METAL gfx::UniformBufferPtr expressionUniformBuffer; Unevaluated::GPUExpressions gpuExpressions; diff --git a/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp b/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp index 28a6154acc6..1db93fd9ee3 100644 --- a/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp @@ -4,19 +4,19 @@ #include #include #include -#include +#include namespace mbgl { +using namespace style; +using namespace shaders; + void LocationIndicatorLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& params) { if (layerGroup.empty()) { return; } - const auto& props = static_cast(*evaluatedProperties); - - const shaders::CommonUBO quadUBO = {/* .matrix */ util::cast(projectionPuck), - /* .color */ Color::black()}; + const auto& props = static_cast(*evaluatedProperties); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { auto& drawableUniforms = drawable.mutableUniformBuffers(); @@ -27,18 +27,20 @@ void LocationIndicatorLayerTweaker::execute(LayerGroupBase& layerGroup, const Pa switch (static_cast(drawable.getType())) { case RenderLocationIndicatorLayer::LocationIndicatorComponentType::Circle: { - shaders::CommonUBO circleUBO = {/* .matrix */ util::cast(projectionCircle), - /* .color */ props.evaluated.get()}; - - drawableUniforms.createOrUpdate(shaders::idCommonUBO, &circleUBO, params.context); + LocationIndicatorDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(projectionCircle), + /* .color = */ props.evaluated.get() + }; + drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); break; } case RenderLocationIndicatorLayer::LocationIndicatorComponentType::CircleOutline: { - shaders::CommonUBO circleUBO = {/* .matrix */ util::cast(projectionCircle), - /* .color */ props.evaluated.get()}; - - drawableUniforms.createOrUpdate(shaders::idCommonUBO, &circleUBO, params.context); + LocationIndicatorDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(projectionCircle), + /* .color = */ props.evaluated.get() + }; + drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); break; } @@ -46,10 +48,15 @@ void LocationIndicatorLayerTweaker::execute(LayerGroupBase& layerGroup, const Pa [[fallthrough]]; case RenderLocationIndicatorLayer::LocationIndicatorComponentType::Puck: [[fallthrough]]; - case RenderLocationIndicatorLayer::LocationIndicatorComponentType::PuckHat: - drawableUniforms.createOrUpdate(shaders::idCommonUBO, &quadUBO, params.context); + case RenderLocationIndicatorLayer::LocationIndicatorComponentType::PuckHat: { + const LocationIndicatorDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(projectionPuck), + /* .color = */ Color::black() + }; + drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); break; - + } + default: assert(false); break; diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index 42db54bd6b3..9044a71c951 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -63,8 +63,13 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idRasterEvaluatedPropsUBO, evaluatedPropsUniformBuffer); + layerUniforms.set(idRasterEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!checkTweakDrawable(drawable)) { return; @@ -95,10 +100,32 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, !parameters.state.isChanging()); } - const RasterDrawableUBO drawableUBO{/*.matrix = */ util::cast(matrix)}; +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i] = { +#else + const RasterDrawableUBO drawableUBO = { +#endif + /*.matrix = */ util::cast(matrix) + }; +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idRasterDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idRasterDrawableUBO, &drawableUBO, parameters.context, true, false); +#endif }); + +#if MLN_UBO_CONSOLIDATION + auto& context = parameters.context; + const size_t drawableUBOVectorSize = sizeof(RasterDrawableUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + layerUniforms.set(idRasterDrawableUBO, drawableUniformBuffer, true, false); +#endif } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.hpp b/src/mbgl/renderer/layers/raster_layer_tweaker.hpp index e56be3c5bee..2e9107351d5 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.hpp @@ -24,6 +24,10 @@ class RasterLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer = nullptr; + +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; +#endif }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp index e23070d6d0a..bc8e551883c 100644 --- a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp +++ b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include #include @@ -1052,7 +1052,7 @@ void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders, } if (!quadShader) { - quadShader = context.getGenericShader(shaders, "CommonTexturedShader"); + quadShader = context.getGenericShader(shaders, "LocationIndicatorTexturedShader"); } if (!quadShader) { @@ -1061,7 +1061,7 @@ void RenderLocationIndicatorLayer::update(gfx::ShaderRegistry& shaders, } if (!circleShader) { - circleShader = context.getGenericShader(shaders, "CommonShader"); + circleShader = context.getGenericShader(shaders, "LocationIndicatorShader"); } if (!circleShader) { diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index 26a2a56f9d2..fa6ca2ede9a 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -19,8 +19,7 @@ #include #if MLN_RENDER_BACKEND_METAL -#include -#include +#include #endif // MLN_RENDER_BACKEND_METAL namespace mbgl { @@ -51,17 +50,6 @@ auto getInterpFactor(const SymbolBucket::PaintProperties& paintProps, bool isTex return std::get(getProperty(paintProps, isText)->interpolationFactor(currentZoom)); } -SymbolInterpolateUBO buildInterpUBO(const SymbolBucket::PaintProperties& paint, const bool t, const float z) { - return {/* .fill_color_t = */ getInterpFactor(paint, t, z), - /* .halo_color_t = */ getInterpFactor(paint, t, z), - /* .opacity_t = */ getInterpFactor(paint, t, z), - /* .halo_width_t = */ getInterpFactor(paint, t, z), - /* .halo_blur_t = */ getInterpFactor(paint, t, z), - /* .padding = */ 0, - 0, - 0}; -} - } // namespace void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { @@ -81,40 +69,32 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete const auto zoom = static_cast(state.getZoom()); if (!evaluatedPropsUniformBuffer || propertiesUpdated) { - const SymbolEvaluatedPropsUBO propsUBO = {/*.text_fill_color=*/constOrDefault(evaluated), - /*.text_halo_color=*/constOrDefault(evaluated), - /*.text_opacity=*/constOrDefault(evaluated), - /*.text_halo_width=*/constOrDefault(evaluated), - /*.text_halo_blur=*/constOrDefault(evaluated), - /* pad */ 0, - /*.icon_fill_color=*/constOrDefault(evaluated), - /*.icon_halo_color=*/constOrDefault(evaluated), - /*.icon_opacity=*/constOrDefault(evaluated), - /*.icon_halo_width=*/constOrDefault(evaluated), - /*.icon_halo_blur=*/constOrDefault(evaluated), - /* pad */ 0}; + const SymbolEvaluatedPropsUBO propsUBO = { + /* .text_fill_color = */ constOrDefault(evaluated), + /* .text_halo_color = */ constOrDefault(evaluated), + /* .text_opacity = */ constOrDefault(evaluated), + /* .text_halo_width = */ constOrDefault(evaluated), + /* .text_halo_blur = */ constOrDefault(evaluated), + /* .pad */ 0, + + /* .icon_fill_color = */ constOrDefault(evaluated), + /* .icon_halo_color = */ constOrDefault(evaluated), + /* .icon_opacity = */ constOrDefault(evaluated), + /* .icon_halo_width = */ constOrDefault(evaluated), + /* .icon_halo_blur = */constOrDefault(evaluated), + /* .pad */ 0 + }; context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idSymbolEvaluatedPropsUBO, evaluatedPropsUniformBuffer); - - const auto getInterpUBO = - [&](const UnwrappedTileID& tileID, bool isText, const SymbolBucket::PaintProperties& paintProps) { - auto result = interpUBOs.insert( - std::make_pair(InterpUBOKey{tileID, isText}, InterpUBOValue{{}, parameters.frameCount})); - if (result.second) { - // new item inserted - const auto interpolateBuf = buildInterpUBO(paintProps, isText, zoom); - result.first->second.ubo = context.createUniformBuffer(&interpolateBuf, sizeof(interpolateBuf)); - } else if (result.first->second.updatedFrame < parameters.frameCount) { - // existing item found, but hasn't been updated this frame - const auto interpolateBuf = buildInterpUBO(paintProps, isText, zoom); - result.first->second.ubo->update(&interpolateBuf, sizeof(interpolateBuf)); - result.first->second.updatedFrame = parameters.frameCount; - } - return result.first->second.ubo; - }; + layerUniforms.set(idSymbolEvaluatedPropsUBO, evaluatedPropsUniformBuffer, false, true); + +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); + std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); +#endif const auto camDist = state.getCameraToCenterDistance(); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { @@ -171,49 +151,75 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete // Unpitched point labels need to have their rotation applied after projection const bool rotateInShader = rotateWithMap && !pitchWithMap && !alongLine; + const auto& sizeBinder = isText ? bucket->textSizeBinder : bucket->iconSizeBinder; + const auto size = sizeBinder->evaluateForZoom(currentZoom); + +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i] = { +#else const SymbolDrawableUBO drawableUBO = { - /*.matrix=*/util::cast(matrix), - /*.label_plane_matrix=*/util::cast(labelPlaneMatrix), - /*.coord_matrix=*/util::cast(glCoordMatrix), - - /*.texsize=*/toArray(getTexSize(drawable, idSymbolImageTexture)), - /*.texsize_icon=*/toArray(getTexSize(drawable, idSymbolImageIconTexture)), +#endif + /* .matrix = */ util::cast(matrix), + /* .label_plane_matrix = */ util::cast(labelPlaneMatrix), + /* .coord_matrix = */ util::cast(glCoordMatrix), - /*.gamma_scale=*/gammaScale, - /*.rotate_symbol=*/rotateInShader, - /*.pad=*/{0}, - }; + /* .texsize = */ toArray(getTexSize(drawable, idSymbolImageTexture)), + /* .texsize_icon = */ toArray(getTexSize(drawable, idSymbolImageIconTexture)), - const auto& sizeBinder = isText ? bucket->textSizeBinder : bucket->iconSizeBinder; - const auto size = sizeBinder->evaluateForZoom(currentZoom); - const auto tileUBO = SymbolTilePropsUBO{ - /* .is_text = */ isText, - /* .is_halo = */ symbolData.isHalo, + /* .is_text_prop = */ isText, + /* .rotate_symbol = */ rotateInShader, /* .pitch_with_map = */ (symbolData.pitchAlignment == style::AlignmentType::Map), /* .is_size_zoom_constant = */ size.isZoomConstant, /* .is_size_feature_constant = */ size.isFeatureConstant, + /* .size_t = */ size.sizeT, /* .size = */ size.size, - /* .padding = */ 0, + + /* .fill_color_t = */ getInterpFactor(paintProperties, isText, zoom), + /* .halo_color_t = */ getInterpFactor(paintProperties, isText, zoom), + /* .opacity_t = */ getInterpFactor(paintProperties, isText, zoom), + /* .halo_width_t = */ getInterpFactor(paintProperties, isText, zoom), + /* .halo_blur_t = */ getInterpFactor(paintProperties, isText, zoom), + }; + +#if MLN_UBO_CONSOLIDATION + tilePropsUBOVector[i] = { +#else + const SymbolTilePropsUBO tilePropsUBO = { +#endif + /* .is_text = */ isText, + /* .is_halo = */ symbolData.isHalo, + /* .gamma_scale= */ gammaScale, + /* .pad1 = */ 0, }; +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idSymbolDrawableUBO, &drawableUBO, context); - drawableUniforms.createOrUpdate(idSymbolTilePropsUBO, &tileUBO, context); - drawableUniforms.set(idSymbolInterpolateUBO, getInterpUBO(tileID, isText, paintProperties)); + drawableUniforms.createOrUpdate(idSymbolDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idSymbolTilePropsUBO, &tilePropsUBO, context, false, true); +#endif }); - // Regularly remove UBOs which are not being updated - constexpr int pruneFrameInterval = 10; - if ((parameters.frameCount % pruneFrameInterval) == 0) { - for (auto i = interpUBOs.begin(); i != interpUBOs.end();) { - if (i->second.updatedFrame < parameters.frameCount) { - i = interpUBOs.erase(i); - } else { - i++; - } - } +#if MLN_UBO_CONSOLIDATION + const size_t drawableUBOVectorSize = sizeof(SymbolDrawableUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + + const size_t tilePropsUBOVectorSize = sizeof(SymbolTilePropsUBO) * tilePropsUBOVector.size(); + if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + } else { + tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } + + layerUniforms.set(idSymbolDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idSymbolTilePropsUBO, tilePropsUniformBuffer, false, true); +#endif } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp index 1ac4fb46baa..1d0f6a50753 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.hpp @@ -23,21 +23,10 @@ class SymbolLayerTweaker : public LayerTweaker { private: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; - // Interpolation UBOs are shared by drawables of the same type (text/icon) in each tile - struct InterpUBOKey { - UnwrappedTileID tileID; - bool isText; - - bool operator==(const InterpUBOKey& other) const { return isText == other.isText && tileID == other.tileID; } - }; - struct InterpUBOValue { - gfx::UniformBufferPtr ubo; - uint64_t updatedFrame = 0; - }; - struct InterpUBOHash { - size_t operator()(const InterpUBOKey& k) const { return util::hash(k.tileID, k.isText); } - }; - mbgl::unordered_map interpUBOs; +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; + gfx::UniformBufferPtr tilePropsUniformBuffer; +#endif }; } // namespace mbgl diff --git a/src/mbgl/renderer/paint_parameters.cpp b/src/mbgl/renderer/paint_parameters.cpp index 1e088cee970..fb94dc9b767 100644 --- a/src/mbgl/renderer/paint_parameters.cpp +++ b/src/mbgl/renderer/paint_parameters.cpp @@ -139,11 +139,13 @@ void PaintParameters::clearStencil() { #endif const std::vector tileUBO = { - shaders::ClipUBO{/*.matrix=*/util::cast(matrixForTile({0, 0, 0})), - /*.stencil_ref=*/0, - /*.pad=*/0, - 0, - 0}}; + shaders::ClipUBO { + /* .matrix = */ util::cast(matrixForTile({0, 0, 0})), + /* .stencil_ref = */ 0, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }}; mtlContext.renderTileClippingMasks(*renderPass, staticData, tileUBO); context.renderingStats().stencilClears++; #elif MLN_RENDER_BACKEND_VULKAN @@ -191,11 +193,13 @@ void PaintParameters::renderTileClippingMasks(const RenderTiles& renderTiles) { tileUBOs.reserve(count); } - tileUBOs.emplace_back(shaders::ClipUBO{/*.matrix=*/util::cast(matrixForTile(tileID)), - /*.stencil_ref=*/static_cast(stencilID), - /*.pad=*/0, - 0, - 0}); + tileUBOs.emplace_back(shaders::ClipUBO { + /* .matrix = */ util::cast(matrixForTile(tileID)), + /* .stencil_ref = */ static_cast(stencilID), + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }); } if (!tileUBOs.empty()) { diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 5ccac52261b..941f3185e85 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -283,11 +283,11 @@ void Renderer::Impl::render(const RenderTree& renderTree, /* .symbol_fade_change = */ parameters.symbolFadeChange, /* .aspect_ratio = */ parameters.state.getSize().aspectRatio(), /* .pixel_ratio = */ parameters.pixelRatio, - /* .zoom = */ static_cast(parameters.state.getZoom()), + /* .map_zoom = */ static_cast(parameters.state.getZoom()), /* .pad1 = */ 0, }; auto& globalUniforms = context.mutableGlobalUniformBuffers(); - globalUniforms.createOrUpdate(shaders::idGlobalPaintParamsUBO, &globalPaintParamsUBO, context); + globalUniforms.createOrUpdate(shaders::idGlobalPaintParamsUBO, &globalPaintParamsUBO, context, true, true); #endif // - 3D PASS diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 52d2bc770df..fa7bbe62551 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -92,21 +92,21 @@ class PolylineLayerTweaker : public LayerTweaker { void execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) override { auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); + layerUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); const LineExpressionUBO exprUBO = { - /* color = */ nullptr, - /* blur = */ nullptr, - /* opacity = */ nullptr, - /* gapwidth = */ nullptr, - /* offset = */ nullptr, - /* width = */ nullptr, - /* floorWidth = */ nullptr, + /* .color = */ nullptr, + /* .blur = */ nullptr, + /* .opacity = */ nullptr, + /* .gapwidth = */ nullptr, + /* .offset = */ nullptr, + /* .width = */ nullptr, + /* .floorWidth = */ nullptr, }; - layerUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context); + layerUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context, true, true); } private: @@ -216,7 +216,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr auto updatedCount = tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) { // update existing drawable auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context); + drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context, true, true); }); return updatedCount; }; @@ -245,22 +245,24 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr for (auto& drawable : debugBuilder->clearDrawables()) { drawable->setTileID(tileID); auto& drawableUniforms = drawable->mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context); + drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context, true, true); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); } }; #if MLN_ENABLE_POLYLINE_DRAWABLES - const shaders::LineEvaluatedPropsUBO linePropertiesUBO = {/*color*/ Color::red(), - /*blur*/ 0.f, - /*opacity*/ 1.f, - /*gapwidth*/ 0.f, - /*offset*/ 0.f, - /*width*/ 4.f, - /*floorwidth*/ 0, - LineExpressionMask::None, - 0}; + const shaders::LineEvaluatedPropsUBO linePropertiesUBO = { + /* .color = */ Color::red(), + /* .blur = */ 0.f, + /* .opacity = */ 1.f, + /* .gapwidth = */ 0.f, + /* .offset = */ 0.f, + /* .width = */ 4.f, + /* .floorwidth = */ 0, + /* .expressionMask = */ LineExpressionMask::None, + /* .pad1 = */ 0 + }; // function to add polylines drawable const auto addPolylineDrawable = [&](TileLayerGroup* tileLayerGroup, const RenderTile& tile) { @@ -285,39 +287,37 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::LineDrawableUBO drawableUBO = {/*matrix = */ util::cast(matrix), - /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - 0, - 0, - 0}; - const shaders::LineInterpolationUBO lineInterpolationUBO = {/*color_t =*/0.f, - /*blur_t =*/0.f, - /*opacity_t =*/0.f, - /*gapwidth_t =*/0.f, - /*offset_t =*/0.f, - /*width_t =*/0.f, - 0, - 0}; + const shaders::LineDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), + + /* .color_t = */ 0.f, + /* .blur_t = */ 0.f, + /* .opacity_t = */ 0.f, + /* .gapwidth_t = */ 0.f, + /* .offset_t = */ 0.f, + /* .width_t = */ 0.f, + /* .pad1 = */ 0 + }; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); - drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context, true, false); #if !MLN_RENDER_BACKEND_VULKAN - drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); const LineExpressionUBO exprUBO = { - /* color = */ nullptr, - /* blur = */ nullptr, - /* opacity = */ nullptr, - /* gapwidth = */ nullptr, - /* offset = */ nullptr, - /* width = */ nullptr, - /* floorWidth = */ nullptr, + /* .color = */ nullptr, + /* .blur = */ nullptr, + /* .opacity = */ nullptr, + /* .gapwidth = */ nullptr, + /* .offset = */ nullptr, + /* .width = */ nullptr, + /* .floorWidth = */ nullptr, }; - drawableUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context, true, true); #endif }; @@ -377,12 +377,14 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto& debugBucket = tile.debugBucket; if (!debugBucket) continue; - const DebugUBO outlineUBO{/*matrix = */ util::cast(tile.matrix), - /*color = */ Color::white(), - /*overlay_scale = */ 1.0f, - 0, - 0, - 0}; + const DebugUBO outlineUBO = { + /* .matrix = */ util::cast(tile.matrix), + /* .color = */ Color::white(), + /* .overlay_scale = */ 1.0f, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; if (0 == updateDrawables(outlineLayerGroup, tileID, outlineUBO)) { addDrawable(outlineLayerGroup, tileID, @@ -393,12 +395,14 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr debugBucket->segments); } - const DebugUBO textUBO{/*matrix = */ util::cast(tile.matrix), - /*color = */ Color::black(), - /*overlay_scale = */ 1.0f, - 0, - 0, - 0}; + const DebugUBO textUBO = { + /* .matrix = */ util::cast(tile.matrix), + /* .color = */ Color::black(), + /* .overlay_scale = */ 1.0f, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; if (0 == updateDrawables(textLayerGroup, tileID, textUBO) && tile.getNeedsRendering()) { addDrawable(textLayerGroup, tileID, @@ -435,12 +439,14 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto& debugBucket = tile.debugBucket; if (!debugBucket) continue; - const DebugUBO debugUBO{/*matrix = */ util::cast(tile.matrix), - /*color = */ Color::red(), - /*overlay_scale = */ 1.0f, - 0, - 0, - 0}; + const DebugUBO debugUBO = { + /* .matrix = */ util::cast(tile.matrix), + /* .color = */ Color::red(), + /* .overlay_scale = */ 1.0f, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; if (0 == updateDrawables(tileLayerGroup, tileID, debugUBO) && tile.getNeedsRendering()) { #if MLN_ENABLE_POLYLINE_DRAWABLES addPolylineDrawable(tileLayerGroup, tile); diff --git a/src/mbgl/shaders/gl/shader_info.cpp b/src/mbgl/shaders/gl/shader_info.cpp index b4bafceb79b..c7c80ec58c3 100644 --- a/src/mbgl/shaders/gl/shader_info.cpp +++ b/src/mbgl/shaders/gl/shader_info.cpp @@ -1,5 +1,4 @@ #include - #include namespace mbgl { @@ -21,7 +20,7 @@ TextureInfo::TextureInfo(std::string_view name_, std::size_t id_) // Background const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, - UniformBlockInfo{"BackgroundLayerUBO", idBackgroundLayerUBO}, + UniformBlockInfo{"BackgroundPropsUBO", idBackgroundPropsUBO}, }; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idBackgroundPosVertexAttribute}, @@ -33,7 +32,7 @@ const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"BackgroundPatternDrawableUBO", idBackgroundDrawableUBO}, - UniformBlockInfo{"BackgroundPatternLayerUBO", idBackgroundLayerUBO}, + UniformBlockInfo{"BackgroundPatternPropsUBO", idBackgroundPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -47,7 +46,6 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO}, - UniformBlockInfo{"CircleInterpolateUBO", idCircleInterpolateUBO}, UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -65,7 +63,8 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"CollisionUBO", idCollisionUBO}, + UniformBlockInfo{"CollisionDrawableUBO", idCollisionDrawableUBO}, + UniformBlockInfo{"CollisionTilePropsUBO", idCollisionTilePropsUBO}, }; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, @@ -79,7 +78,8 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { - UniformBlockInfo{"CollisionUBO", idCollisionUBO}, + UniformBlockInfo{"CollisionDrawableUBO", idCollisionDrawableUBO}, + UniformBlockInfo{"CollisionTilePropsUBO", idCollisionTilePropsUBO}, }; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, @@ -93,7 +93,6 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { UniformBlockInfo{"CustomSymbolIconDrawableUBO", idCustomSymbolDrawableUBO}, - UniformBlockInfo{"CustomSymbolIconParametersUBO", idCustomSymbolParametersUBO}, }; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idCustomSymbolPosVertexAttribute}, @@ -117,7 +116,6 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { UniformBlockInfo{"FillDrawableUBO", idFillDrawableUBO}, - UniformBlockInfo{"FillInterpolateUBO", idFillInterpolateUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -132,7 +130,6 @@ const std::vector ShaderInfo ShaderInfo::attributes = { @@ -148,7 +145,6 @@ const std::vector ShaderInfo ShaderInfo::attributes = { @@ -167,7 +163,6 @@ const std::vector UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillOutlinePatternTilePropsUBO", idFillTilePropsUBO}, - UniformBlockInfo{"FillOutlinePatternInterpolateUBO", idFillInterpolateUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = @@ -201,7 +196,6 @@ const std::vector ShaderInfo::uniformBlocks = { UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, - UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -219,7 +213,6 @@ const std::vector UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, - UniformBlockInfo{"FillExtrusionInterpolateUBO", idFillExtrusionInterpolateUBO}, UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, }; const std::vector @@ -238,7 +231,6 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { UniformBlockInfo{"HeatmapDrawableUBO", idHeatmapDrawableUBO}, - UniformBlockInfo{"HeatmapInterpolateUBO", idHeatmapInterpolateUBO}, UniformBlockInfo{"HeatmapEvaluatedPropsUBO", idHeatmapEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -266,6 +258,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { UniformBlockInfo{"HillshadePrepareDrawableUBO", idHillshadePrepareDrawableUBO}, + UniformBlockInfo{"HillshadePrepareTilePropsUBO", idHillshadePrepareTilePropsUBO}, }; const std::vector ShaderInfo::attributes = { AttributeInfo{"a_pos", idHillshadePosVertexAttribute}, @@ -278,6 +271,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { UniformBlockInfo{"HillshadeDrawableUBO", idHillshadeDrawableUBO}, + UniformBlockInfo{"HillshadeTilePropsUBO", idHillshadeTilePropsUBO}, UniformBlockInfo{"HillshadeEvaluatedPropsUBO", idHillshadeEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -292,7 +286,6 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LineDrawableUBO", idLineDrawableUBO}, - UniformBlockInfo{"LineInterpolationUBO", idLineInterpolationUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -312,7 +305,6 @@ const std::vector ShaderInfo ShaderInfo::attributes = { @@ -333,8 +325,7 @@ const std::vector ShaderInfo ShaderInfo::attributes = { @@ -356,7 +347,7 @@ const std::vector ShaderInfo ShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LineSDFDrawableUBO", idLineDrawableUBO}, - UniformBlockInfo{"LineSDFInterpolationUBO", idLineInterpolationUBO}, + UniformBlockInfo{"LineSDFTilePropsUBO", idLineTilePropsUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -393,7 +384,6 @@ const std::vector ShaderInfo ShaderInfo::attributes = { @@ -414,7 +404,6 @@ const std::vector UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, - UniformBlockInfo{"SymbolInterpolateUBO", idSymbolInterpolateUBO}, UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = { @@ -439,7 +428,6 @@ const std::vector UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, - UniformBlockInfo{"SymbolInterpolateUBO", idSymbolInterpolateUBO}, UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, }; const std::vector ShaderInfo::attributes = diff --git a/src/mbgl/shaders/mtl/background.cpp b/src/mbgl/shaders/mtl/background.cpp index e2556339c4f..16a6b5c0f97 100644 --- a/src/mbgl/shaders/mtl/background.cpp +++ b/src/mbgl/shaders/mtl/background.cpp @@ -1,18 +1,39 @@ #include #include -#include namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +// +// Background + +using BackgroundShaderSource = ShaderSource; + +const std::array BackgroundShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{false, true, sizeof(BackgroundLayerUBO), idBackgroundLayerUBO}, + UniformBlockInfo{false, true, sizeof(BackgroundPropsUBO), idBackgroundPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array BackgroundShaderSource::attributes = { AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; -const std::array ShaderSource::textures = {}; +const std::array BackgroundShaderSource::textures = {}; + +// +// Background pattern + +using BackgroundPatternShaderSource = ShaderSource; + +const std::arrayBackgroundPatternShaderSource::uniforms = { + UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, + UniformBlockInfo{true, true, sizeof(BackgroundPatternPropsUBO), idBackgroundPropsUBO}, +}; +const std::array BackgroundPatternShaderSource::attributes = { + AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, +}; +const std::array BackgroundPatternShaderSource::textures = { + TextureInfo{0, idBackgroundImageTexture} +}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/mtl/background_pattern.cpp b/src/mbgl/shaders/mtl/background_pattern.cpp deleted file mode 100644 index 3eb91e51300..00000000000 --- a/src/mbgl/shaders/mtl/background_pattern.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -namespace mbgl { -namespace shaders { - -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{true, true, sizeof(BackgroundPatternLayerUBO), idBackgroundLayerUBO}, -}; -const std::array - ShaderSource::attributes = { - AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idBackgroundImageTexture}}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/circle.cpp b/src/mbgl/shaders/mtl/circle.cpp index 7afbfa9ac67..1e2898afe77 100644 --- a/src/mbgl/shaders/mtl/circle.cpp +++ b/src/mbgl/shaders/mtl/circle.cpp @@ -4,13 +4,14 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using CircleShaderSource = ShaderSource; + +const std::array CircleShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(CircleDrawableUBO), idCircleDrawableUBO}, - UniformBlockInfo{true, false, sizeof(CircleInterpolateUBO), idCircleInterpolateUBO}, UniformBlockInfo{true, true, sizeof(CircleEvaluatedPropsUBO), idCircleEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array CircleShaderSource::attributes = { AttributeInfo{circleUBOCount + 0, gfx::AttributeDataType::Short2, idCirclePosVertexAttribute}, AttributeInfo{circleUBOCount + 1, gfx::AttributeDataType::Float4, idCircleColorVertexAttribute}, AttributeInfo{circleUBOCount + 2, gfx::AttributeDataType::Float2, idCircleRadiusVertexAttribute}, @@ -20,7 +21,7 @@ const std::array ShaderSource ShaderSource::textures = {}; +const std::array CircleShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/mtl/clipping_mask.cpp b/src/mbgl/shaders/mtl/clipping_mask.cpp index 5b97d69a982..52ba6e0ba9a 100644 --- a/src/mbgl/shaders/mtl/clipping_mask.cpp +++ b/src/mbgl/shaders/mtl/clipping_mask.cpp @@ -3,15 +3,15 @@ namespace mbgl { namespace shaders { -using ShaderType = ShaderSource; +using ClippingMaskShaderSource = ShaderSource; -const std::array ShaderType::uniforms = { +const std::array ClippingMaskShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(ClipUBO), idClippingMaskUBO}, }; -const std::array ShaderType::attributes = { +const std::array ClippingMaskShaderSource::attributes = { AttributeInfo{clippingMaskUBOCount + 0, gfx::AttributeDataType::Float3, idClippingMaskPosVertexAttribute}, }; -const std::array ShaderType::textures = {}; +const std::array ClippingMaskShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/mtl/collision.cpp b/src/mbgl/shaders/mtl/collision.cpp new file mode 100644 index 00000000000..61c3d8dfb3c --- /dev/null +++ b/src/mbgl/shaders/mtl/collision.cpp @@ -0,0 +1,43 @@ +#include +#include + +namespace mbgl { +namespace shaders { + +// +// Collision box + +using CollisionBoxShaderSource = ShaderSource; + +const std::array CollisionBoxShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, + UniformBlockInfo{true, false, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, +}; +const std::array CollisionBoxShaderSource::attributes = { + AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, + AttributeInfo{collisionUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, + AttributeInfo{collisionUBOCount + 4, gfx::AttributeDataType::Float2, idCollisionShiftVertexAttribute}, +}; +const std::array CollisionBoxShaderSource::textures = {}; + +// +// Collision circle + +using CollisionCircleShaderSource = ShaderSource; + +const std::array CollisionCircleShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, +}; +const std::array CollisionCircleShaderSource::attributes = { + AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, + AttributeInfo{collisionUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, +}; +const std::array CollisionCircleShaderSource::textures = {}; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/collision_box.cpp b/src/mbgl/shaders/mtl/collision_box.cpp deleted file mode 100644 index 2eadf5bf09a..00000000000 --- a/src/mbgl/shaders/mtl/collision_box.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -namespace mbgl { -namespace shaders { - -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(CollisionUBO), idCollisionUBO}, -}; -const std::array ShaderSource::attributes = { - AttributeInfo{collisionDrawableUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, - AttributeInfo{collisionDrawableUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, - AttributeInfo{collisionDrawableUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, - AttributeInfo{collisionDrawableUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, - AttributeInfo{collisionDrawableUBOCount + 4, gfx::AttributeDataType::Float2, idCollisionShiftVertexAttribute}, -}; -const std::array ShaderSource::textures = {}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/collision_circle.cpp b/src/mbgl/shaders/mtl/collision_circle.cpp deleted file mode 100644 index bc407e1d235..00000000000 --- a/src/mbgl/shaders/mtl/collision_circle.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -namespace mbgl { -namespace shaders { - -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(CollisionUBO), idCollisionUBO}, -}; -const std::array ShaderSource::attributes = - { - AttributeInfo{collisionDrawableUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, - AttributeInfo{ - collisionDrawableUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, - AttributeInfo{collisionDrawableUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, - AttributeInfo{collisionDrawableUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, -}; -const std::array ShaderSource::textures = {}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp index 8b104bd4497..d98f363e4eb 100644 --- a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp @@ -4,18 +4,16 @@ namespace mbgl { namespace shaders { -const std::array - ShaderSource::uniforms = { +using CustomSymbolIconShaderSource = ShaderSource; + +const std::array CustomSymbolIconShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, - UniformBlockInfo{true, false, sizeof(CustomSymbolIconParametersUBO), idCustomSymbolParametersUBO}, }; -const std::array ShaderSource::attributes = { - // always attributes - AttributeInfo{customSymbolDrawableUBOCount + 0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, - AttributeInfo{customSymbolDrawableUBOCount + 1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, +const std::array CustomSymbolIconShaderSource::attributes = { + AttributeInfo{customSymbolUBOCount + 0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, + AttributeInfo{customSymbolUBOCount + 1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array CustomSymbolIconShaderSource::textures = { TextureInfo{0, idCustomSymbolImageTexture}, }; diff --git a/src/mbgl/shaders/mtl/debug.cpp b/src/mbgl/shaders/mtl/debug.cpp index d1be225ad9a..8e8918dd55b 100644 --- a/src/mbgl/shaders/mtl/debug.cpp +++ b/src/mbgl/shaders/mtl/debug.cpp @@ -4,13 +4,15 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using DebugShaderSource = ShaderSource; + +const std::array DebugShaderSource::uniforms = { UniformBlockInfo{true, true, sizeof(DebugUBO), idDebugUBO}, }; -const std::array ShaderSource::attributes = { - AttributeInfo{debugDrawableUBOCount + 0, gfx::AttributeDataType::Short2, idDebugPosVertexAttribute}, +const std::array DebugShaderSource::attributes = { + AttributeInfo{debugUBOCount + 0, gfx::AttributeDataType::Short2, idDebugPosVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array DebugShaderSource::textures = { TextureInfo{0, idDebugOverlayTexture}, }; diff --git a/src/mbgl/shaders/mtl/fill.cpp b/src/mbgl/shaders/mtl/fill.cpp index 80f124f7127..2f18476da20 100644 --- a/src/mbgl/shaders/mtl/fill.cpp +++ b/src/mbgl/shaders/mtl/fill.cpp @@ -4,81 +4,96 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +// +// Fill + +using FillShaderSource = ShaderSource; + +const std::array FillShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(FillDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillInterpolateUBO), idFillInterpolateUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array FillShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::Float4, idFillColorVertexAttribute}, AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; -const std::array ShaderSource::textures = {}; +const std::array FillShaderSource::textures = {}; + +// +// Fill outline -const std::array ShaderSource::uniforms = { +using FillOutlineShaderSource = ShaderSource; + +const std::array FillOutlineShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(FillOutlineDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlineInterpolateUBO), idFillInterpolateUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array FillOutlineShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::Float4, idFillOutlineColorVertexAttribute}, AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; -const std::array ShaderSource::textures = {}; +const std::array FillOutlineShaderSource::textures = {}; + +// +// Fill pattern -const std::array ShaderSource::uniforms = { +using FillPatternShaderSource = ShaderSource; + +const std::array FillPatternShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(FillPatternDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillPatternDrawableUBO), idFillDrawableUBO}, UniformBlockInfo{true, true, sizeof(FillPatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(FillPatternInterpolateUBO), idFillInterpolateUBO}, UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array FillPatternShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, AttributeInfo{fillUBOCount + 3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array FillPatternShaderSource::textures = { TextureInfo{0, idFillImageTexture}, }; -const std::array - ShaderSource::uniforms = { +// +// Fill pattern outline + +using FillOutlinePatternShaderSource = ShaderSource; + +const std::array FillOutlinePatternShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlinePatternInterpolateUBO), idFillInterpolateUBO}, UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array - ShaderSource::attributes = { +const std::array FillOutlinePatternShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, AttributeInfo{fillUBOCount + 3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; -const std::array ShaderSource::textures = - { +const std::array FillOutlinePatternShaderSource::textures = { TextureInfo{0, idFillImageTexture}, }; -const std::array - ShaderSource::uniforms = { +// +// Fill outline triangulated + +using FillOutlineTriangulatedShaderSource = ShaderSource; + +const std::array FillOutlineTriangulatedShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array - ShaderSource::attributes = { +const std::array FillOutlineTriangulatedShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, }; -const std::array - ShaderSource::textures = {}; +const std::array FillOutlineTriangulatedShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/mtl/fill_extrusion.cpp b/src/mbgl/shaders/mtl/fill_extrusion.cpp index 4a329a7cd5e..7eb5cea0bb0 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion.cpp @@ -4,20 +4,46 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = - { +// +// Fill extrusion + +using FillExtrusionShaderSource = ShaderSource; + +const std::array FillExtrusionShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array FillExtrusionShaderSource::attributes = { AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 2, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 3, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 4, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, }; -const std::array ShaderSource::textures = {}; +const std::array FillExtrusionShaderSource::textures = {}; + +// +// Fill extrusion pattern + +using FillExtrusionPatternShaderSource = ShaderSource; + +const std::array FillExtrusionPatternShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, +}; +const std::array FillExtrusionPatternShaderSource::attributes = { + AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, + AttributeInfo{fillExtrusionUBOCount + 5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, +}; +const std::array FillExtrusionPatternShaderSource::textures = { + TextureInfo{0, idFillExtrusionImageTexture}, +}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp b/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp deleted file mode 100644 index 5180d8da447..00000000000 --- a/src/mbgl/shaders/mtl/fill_extrusion_pattern.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - -namespace mbgl { -namespace shaders { - -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, -}; -const std::array ShaderSource::attributes = { - AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, - AttributeInfo{ - fillExtrusionUBOCount + 4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, -}; -const std::array - ShaderSource::textures = { - TextureInfo{0, idFillExtrusionImageTexture}, -}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/heatmap.cpp b/src/mbgl/shaders/mtl/heatmap.cpp index c63e3acd745..27b234757a6 100644 --- a/src/mbgl/shaders/mtl/heatmap.cpp +++ b/src/mbgl/shaders/mtl/heatmap.cpp @@ -4,17 +4,18 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using HeatmapShaderSource = ShaderSource; + +const std::array HeatmapShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(HeatmapDrawableUBO), idHeatmapDrawableUBO}, - UniformBlockInfo{true, false, sizeof(HeatmapInterpolateUBO), idHeatmapInterpolateUBO}, UniformBlockInfo{true, true, sizeof(HeatmapEvaluatedPropsUBO), idHeatmapEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array HeatmapShaderSource::attributes = { AttributeInfo{heatmapUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, AttributeInfo{heatmapUBOCount + 1, gfx::AttributeDataType::Float2, idHeatmapWeightVertexAttribute}, AttributeInfo{heatmapUBOCount + 2, gfx::AttributeDataType::Float2, idHeatmapRadiusVertexAttribute}, }; -const std::array ShaderSource::textures = {}; +const std::array HeatmapShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/mtl/heatmap_texture.cpp b/src/mbgl/shaders/mtl/heatmap_texture.cpp index b536695beae..155dfaaa5f9 100644 --- a/src/mbgl/shaders/mtl/heatmap_texture.cpp +++ b/src/mbgl/shaders/mtl/heatmap_texture.cpp @@ -4,16 +4,16 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = - { +using HeatmapTextureShaderSource = ShaderSource; + +const std::array HeatmapTextureShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, }; -const std::array ShaderSource::attributes = - { +const std::array HeatmapTextureShaderSource::attributes = { AttributeInfo{heatmapTextureUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array HeatmapTextureShaderSource::textures = { TextureInfo{0, idHeatmapImageTexture}, TextureInfo{1, idHeatmapColorRampTexture}, }; diff --git a/src/mbgl/shaders/mtl/hillshade.cpp b/src/mbgl/shaders/mtl/hillshade.cpp index fbd93012a8c..0a7daa68eaa 100644 --- a/src/mbgl/shaders/mtl/hillshade.cpp +++ b/src/mbgl/shaders/mtl/hillshade.cpp @@ -4,15 +4,18 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, +using HillshadeShaderSource = ShaderSource; + +const std::array HillshadeShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, + UniformBlockInfo{false, true, sizeof(HillshadeTilePropsUBO), idHillshadeTilePropsUBO}, UniformBlockInfo{false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array HillshadeShaderSource::attributes = { AttributeInfo{hillshadeUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, AttributeInfo{hillshadeUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array HillshadeShaderSource::textures = { TextureInfo{0, idHillshadeImageTexture}, }; diff --git a/src/mbgl/shaders/mtl/hillshade_prepare.cpp b/src/mbgl/shaders/mtl/hillshade_prepare.cpp index f5eea79ea21..60df912c35c 100644 --- a/src/mbgl/shaders/mtl/hillshade_prepare.cpp +++ b/src/mbgl/shaders/mtl/hillshade_prepare.cpp @@ -4,17 +4,17 @@ namespace mbgl { namespace shaders { -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, +using HillshadePrepareShaderSource = ShaderSource; + +const std::array HillshadePrepareShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, + UniformBlockInfo{true, true, sizeof(HillshadePrepareTilePropsUBO), idHillshadePrepareTilePropsUBO}, }; -const std::array ShaderSource::attributes = { - AttributeInfo{hillshadePrepareDrawableUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, - AttributeInfo{ - hillshadePrepareDrawableUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, +const std::array HillshadePrepareShaderSource::attributes = { + AttributeInfo{hillshadePrepareUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, + AttributeInfo{hillshadePrepareUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array HillshadePrepareShaderSource::textures = { TextureInfo{0, idHillshadeImageTexture}, }; diff --git a/src/mbgl/shaders/mtl/line.cpp b/src/mbgl/shaders/mtl/line.cpp index d91ba21a8db..afb607c5c86 100644 --- a/src/mbgl/shaders/mtl/line.cpp +++ b/src/mbgl/shaders/mtl/line.cpp @@ -4,14 +4,18 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +// +// Line + +using LineShaderSource = ShaderSource; + +const std::array LineShaderSource::uniforms = { UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(idLineDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, false, sizeof(LineInterpolationUBO), idLineInterpolationUBO}, + UniformBlockInfo{true, false, sizeof(LineDrawableUBO), idLineDrawableUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, UniformBlockInfo{true, true, sizeof(LineExpressionUBO), idLineExpressionUBO}, }; -const std::array ShaderSource::attributes = { +const std::array LineShaderSource::attributes = { AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, @@ -21,15 +25,19 @@ const std::array ShaderSource ShaderSource::textures = {}; +const std::array LineShaderSource::textures = {}; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, +// +// Line gradient + +using LineGradientShaderSource = ShaderSource; + +const std::array LineGradientShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(LineGradientDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, false, sizeof(LineGradientInterpolationUBO), idLineInterpolationUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array LineGradientShaderSource::attributes = { AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, @@ -38,19 +46,23 @@ const std::array ShaderSource ShaderSource::textures = { +const std::array LineGradientShaderSource::textures = { TextureInfo{0, idLineImageTexture}, }; -const std::array ShaderSource::uniforms = { +// +// Line pattern + +using LinePatternShaderSource = ShaderSource; + +const std::array LinePatternShaderSource::uniforms = { UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(LinePatternDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, false, sizeof(LinePatternInterpolationUBO), idLineInterpolationUBO}, - UniformBlockInfo{true, true, sizeof(LinePatternTilePropertiesUBO), idLineTilePropertiesUBO}, + UniformBlockInfo{true, false, sizeof(LinePatternDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{false, true, sizeof(LinePatternTilePropsUBO), idLineTilePropsUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, UniformBlockInfo{true, true, sizeof(LineExpressionUBO), idLineExpressionUBO}, }; -const std::array ShaderSource::attributes = { +const std::array LinePatternShaderSource::attributes = { AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, @@ -61,18 +73,23 @@ const std::array ShaderSource ShaderSource::textures = { +const std::array LinePatternShaderSource::textures = { TextureInfo{0, idLineImageTexture}, }; -const std::array ShaderSource::uniforms = { +// +// Line SDF + +using LineSDFShaderSource = ShaderSource; + +const std::array LineSDFShaderSource::uniforms = { UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(LineSDFDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, false, sizeof(LineSDFInterpolationUBO), idLineInterpolationUBO}, + UniformBlockInfo{true, false, sizeof(LineSDFDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{false, true, sizeof(LineSDFTilePropsUBO), idLineTilePropsUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, UniformBlockInfo{true, true, sizeof(LineExpressionUBO), idLineExpressionUBO}, }; -const std::array ShaderSource::attributes = { +const std::array LineSDFShaderSource::attributes = { AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, AttributeInfo{lineUBOCount + 2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, @@ -83,7 +100,7 @@ const std::array ShaderSource ShaderSource::textures = { +const std::array LineSDFShaderSource::textures = { TextureInfo{0, idLineImageTexture}, }; diff --git a/src/mbgl/shaders/mtl/raster.cpp b/src/mbgl/shaders/mtl/raster.cpp index cc13205d432..f9ae0c00390 100644 --- a/src/mbgl/shaders/mtl/raster.cpp +++ b/src/mbgl/shaders/mtl/raster.cpp @@ -4,15 +4,17 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using RasterShaderSource = ShaderSource; + +const std::array RasterShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(RasterDrawableUBO), idRasterDrawableUBO}, UniformBlockInfo{true, true, sizeof(RasterEvaluatedPropsUBO), idRasterEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array RasterShaderSource::attributes = { AttributeInfo{rasterUBOCount + 0, gfx::AttributeDataType::Short2, idRasterPosVertexAttribute}, AttributeInfo{rasterUBOCount + 1, gfx::AttributeDataType::Short2, idRasterTexturePosVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array RasterShaderSource::textures = { TextureInfo{0, idRasterImage0Texture}, TextureInfo{1, idRasterImage1Texture}, }; diff --git a/src/mbgl/shaders/mtl/symbol.cpp b/src/mbgl/shaders/mtl/symbol.cpp new file mode 100644 index 00000000000..a8435cf3406 --- /dev/null +++ b/src/mbgl/shaders/mtl/symbol.cpp @@ -0,0 +1,94 @@ +#include +#include + +namespace mbgl { +namespace shaders { + +// +// Symbol icon + +using SymbolIconShaderSource = ShaderSource; + +const std::array SymbolIconShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, +}; +const std::array SymbolIconShaderSource::attributes = { + // always attributes + AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + + // sometimes uniforms + AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, +}; +const std::array SymbolIconShaderSource::textures = { + TextureInfo{0, idSymbolImageTexture}, +}; + +// +// Symbol sdf + +using SymbolSDFIconShaderSource = ShaderSource; + +const std::array SymbolSDFIconShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, +}; +const std::array SymbolSDFIconShaderSource::attributes = { + // always attributes + AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + + // sometimes uniforms + AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{symbolUBOCount + 9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, +}; +const std::array SymbolSDFIconShaderSource::textures = { + TextureInfo{0, idSymbolImageTexture}, +}; + +// +// Symbol icon and text + +using SymbolTextAndIconShaderSource = ShaderSource; + +const std::array SymbolTextAndIconShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, +}; +const std::array SymbolTextAndIconShaderSource::attributes = { + // always attributes + AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + + // sometimes uniforms + AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, +}; +const std::array SymbolTextAndIconShaderSource::textures = { + TextureInfo{0, idSymbolImageTexture}, + TextureInfo{1, idSymbolImageIconTexture}, +}; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/symbol_icon.cpp b/src/mbgl/shaders/mtl/symbol_icon.cpp deleted file mode 100644 index d25af5b666b..00000000000 --- a/src/mbgl/shaders/mtl/symbol_icon.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -namespace mbgl { -namespace shaders { - -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; -const std::array ShaderSource::attributes = { - // always attributes - AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, - - // sometimes uniforms - AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idSymbolImageTexture}, -}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/symbol_sdf.cpp b/src/mbgl/shaders/mtl/symbol_sdf.cpp deleted file mode 100644 index e288aab5c14..00000000000 --- a/src/mbgl/shaders/mtl/symbol_sdf.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -namespace mbgl { -namespace shaders { - -const std::array ShaderSource::uniforms = - { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; -const std::array ShaderSource::attributes = - { - // always attributes - AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, - - // sometimes uniforms - AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{symbolUBOCount + 9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idSymbolImageTexture}, -}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp b/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp deleted file mode 100644 index 226a051cf91..00000000000 --- a/src/mbgl/shaders/mtl/symbol_text_and_icon.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -namespace mbgl { -namespace shaders { - -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; -const std::array - ShaderSource::attributes = { - // always attributes - AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, - - // sometimes uniforms - AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idSymbolImageTexture}, - TextureInfo{1, idSymbolImageIconTexture}, -}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/mtl/widevector.cpp b/src/mbgl/shaders/mtl/widevector.cpp new file mode 100644 index 00000000000..1afee2968d1 --- /dev/null +++ b/src/mbgl/shaders/mtl/widevector.cpp @@ -0,0 +1,27 @@ +#include +#include + +namespace mbgl { +namespace shaders { + +using WideVectorShaderSource = ShaderSource; + +const std::array WideVectorShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(WideVectorUniformsUBO), idWideVectorUniformsUBO}, + UniformBlockInfo{true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO}, +}; +const std::array WideVectorShaderSource::attributes = { + AttributeInfo{wideVectorUBOCount + 0, gfx::AttributeDataType::Float3, idWideVectorScreenPos}, + AttributeInfo{wideVectorUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor}, + AttributeInfo{wideVectorUBOCount + 2, gfx::AttributeDataType::Int, idWideVectorIndex}, +}; +const std::array WideVectorShaderSource::instanceAttributes = { + AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter}, + AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Float4, idWideVectorInstanceColor}, + AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstancePrevious}, + AttributeInfo{wideVectorUBOCount + 3, gfx::AttributeDataType::Int, idWideVectorInstanceNext}, +}; +const std::array WideVectorShaderSource::textures = {}; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/background.cpp b/src/mbgl/shaders/vulkan/background.cpp index 66d8de494f2..1096ddcef38 100644 --- a/src/mbgl/shaders/vulkan/background.cpp +++ b/src/mbgl/shaders/vulkan/background.cpp @@ -5,26 +5,36 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +// +// Background + +using BackgroundShaderSource = ShaderSource; + +const std::array BackgroundShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{false, true, sizeof(BackgroundLayerUBO), idBackgroundLayerUBO}, + UniformBlockInfo{false, true, sizeof(BackgroundPropsUBO), idBackgroundPropsUBO}, }; -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idBackgroundPosVertexAttribute}, +const std::array BackgroundShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; +const std::array BackgroundShaderSource::textures = {}; + +// +// Background pattern -const std::array - ShaderSource::uniforms = { +using BackgroundPatternShaderSource = ShaderSource; + +const std::arrayBackgroundPatternShaderSource::uniforms = { UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{true, true, sizeof(BackgroundPatternLayerUBO), idBackgroundLayerUBO}, + UniformBlockInfo{true, true, sizeof(BackgroundPatternPropsUBO), idBackgroundPropsUBO}, +}; +const std::array BackgroundPatternShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; -const std::array - ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idBackgroundPosVertexAttribute}, +const std::array BackgroundPatternShaderSource::textures = { + TextureInfo{0, idBackgroundImageTexture} }; -const std::array ShaderSource::textures = - {TextureInfo{0, idBackgroundImageTexture}}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/circle.cpp b/src/mbgl/shaders/vulkan/circle.cpp index d10442520a8..9e079d984c4 100644 --- a/src/mbgl/shaders/vulkan/circle.cpp +++ b/src/mbgl/shaders/vulkan/circle.cpp @@ -5,13 +5,14 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using CircleShaderSource = ShaderSource; + +const std::array CircleShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(CircleDrawableUBO), idCircleDrawableUBO}, - UniformBlockInfo{true, false, sizeof(CircleInterpolateUBO), idCircleInterpolateUBO}, UniformBlockInfo{true, true, sizeof(CircleEvaluatedPropsUBO), idCircleEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array CircleShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idCirclePosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float4, idCircleColorVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float2, idCircleRadiusVertexAttribute}, @@ -21,6 +22,7 @@ const std::array ShaderSource CircleShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/clipping_mask.cpp b/src/mbgl/shaders/vulkan/clipping_mask.cpp index 6a96a21b35b..f26fc8669f5 100644 --- a/src/mbgl/shaders/vulkan/clipping_mask.cpp +++ b/src/mbgl/shaders/vulkan/clipping_mask.cpp @@ -3,8 +3,13 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::attributes = - {AttributeInfo{0, gfx::AttributeDataType::Short2, idClippingMaskPosVertexAttribute}}; +using ClippingMaskShaderSource = ShaderSource; + +const std::array ClippingMaskShaderSource::uniforms = {}; +const std::array ClippingMaskShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Short2, idClippingMaskPosVertexAttribute}, +}; +const std::array ClippingMaskShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/collision.cpp b/src/mbgl/shaders/vulkan/collision.cpp index 733c8303147..0e00e65012d 100644 --- a/src/mbgl/shaders/vulkan/collision.cpp +++ b/src/mbgl/shaders/vulkan/collision.cpp @@ -5,29 +5,40 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = - { - UniformBlockInfo{true, true, sizeof(CollisionUBO), idCollisionUBO}, +// +// Collision box + +using CollisionBoxShaderSource = ShaderSource; + +const std::array CollisionBoxShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, + UniformBlockInfo{true, false, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array CollisionBoxShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, AttributeInfo{3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, AttributeInfo{4, gfx::AttributeDataType::Float2, idCollisionShiftVertexAttribute}, }; +const std::array CollisionBoxShaderSource::textures = {}; + +// +// Collision circle + +using CollisionCircleShaderSource = ShaderSource; -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(CollisionUBO), idCollisionUBO}, +const std::array CollisionCircleShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, }; -const std::array - ShaderSource::attributes = { +const std::array CollisionCircleShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, AttributeInfo{3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, }; +const std::array CollisionCircleShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/common.cpp b/src/mbgl/shaders/vulkan/common.cpp deleted file mode 100644 index 52531b3479a..00000000000 --- a/src/mbgl/shaders/vulkan/common.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -namespace mbgl { -namespace shaders { - -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(CommonUBO), idCommonUBO}, -}; -const std::array ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute}, -}; - -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(CommonUBO), idCommonUBO}, -}; -const std::array ShaderSource::attributes = - { - AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Float2, idCommonTexVertexAttribute}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idCommonTexture}, -}; - -} // namespace shaders -} // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp b/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp new file mode 100644 index 00000000000..3fb20a04354 --- /dev/null +++ b/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +namespace mbgl { +namespace shaders { + +using CustomSymbolIconShaderSource = ShaderSource; + +const std::array CustomSymbolIconShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, +}; +const std::array CustomSymbolIconShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, +}; +const std::array CustomSymbolIconShaderSource::textures = { + TextureInfo{0, idCustomSymbolImageTexture}, +}; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/debug.cpp b/src/mbgl/shaders/vulkan/debug.cpp index a48c2d00462..761b12dd186 100644 --- a/src/mbgl/shaders/vulkan/debug.cpp +++ b/src/mbgl/shaders/vulkan/debug.cpp @@ -5,13 +5,15 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using DebugShaderSource = ShaderSource; + +const std::array DebugShaderSource::uniforms = { UniformBlockInfo{true, true, sizeof(DebugUBO), idDebugUBO}, }; -const std::array ShaderSource::attributes = { +const std::array DebugShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idDebugPosVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array DebugShaderSource::textures = { TextureInfo{0, idDebugOverlayTexture}, }; diff --git a/src/mbgl/shaders/vulkan/fill.cpp b/src/mbgl/shaders/vulkan/fill.cpp index dabd506de14..2f46c2463dc 100644 --- a/src/mbgl/shaders/vulkan/fill.cpp +++ b/src/mbgl/shaders/vulkan/fill.cpp @@ -1,119 +1,100 @@ #include #include #include -#include namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +// +// Fill + +using FillShaderSource = ShaderSource; + +const std::array FillShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(FillDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillInterpolateUBO), idFillInterpolateUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array FillShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float4, idFillColorVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; +const std::array FillShaderSource::textures = {}; -const std::array ShaderSource::uniforms = { +// +// Fill outline + +using FillOutlineShaderSource = ShaderSource; + +const std::array FillOutlineShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(FillOutlineDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlineInterpolateUBO), idFillInterpolateUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array FillOutlineShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float4, idFillOutlineColorVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; +const std::array FillOutlineShaderSource::textures = {}; -const std::array ShaderSource::uniforms = { +// +// Fill pattern + +using FillPatternShaderSource = ShaderSource; + +const std::array FillPatternShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(FillPatternDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillPatternDrawableUBO), idFillDrawableUBO}, UniformBlockInfo{true, true, sizeof(FillPatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(FillPatternInterpolateUBO), idFillInterpolateUBO}, UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array FillPatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, AttributeInfo{3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array FillPatternShaderSource::textures = { TextureInfo{0, idFillImageTexture}, }; -const std::array - ShaderSource::uniforms = { +// +// Fill pattern outline + +using FillOutlinePatternShaderSource = ShaderSource; + +const std::array FillOutlinePatternShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlinePatternInterpolateUBO), idFillInterpolateUBO}, UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array - ShaderSource::attributes = { +const std::array FillOutlinePatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, AttributeInfo{3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; -const std::array ShaderSource::textures = - { +const std::array FillOutlinePatternShaderSource::textures = { TextureInfo{0, idFillImageTexture}, }; -const std::array - ShaderSource::uniforms = { +// +// Fill outline triangulated + +using FillOutlineTriangulatedShaderSource = ShaderSource; + +const std::array FillOutlineTriangulatedShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; -const std::array - ShaderSource::attributes = { +const std::array FillOutlineTriangulatedShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, }; - -const std::array ShaderSource::uniforms = - { - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, -}; -const std::array ShaderSource::attributes = - { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idFillExtrusionBaseVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float2, idFillExtrusionHeightVertexAttribute}, -}; - -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionInterpolateUBO), idFillExtrusionInterpolateUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, -}; -const std::array - ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float2, idFillExtrusionBaseVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idFillExtrusionHeightVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, -}; -const std::array - ShaderSource::textures = { - TextureInfo{0, idFillExtrusionImageTexture}, -}; +const std::array FillOutlineTriangulatedShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/fill_extrusion.cpp b/src/mbgl/shaders/vulkan/fill_extrusion.cpp new file mode 100644 index 00000000000..a10e747daf0 --- /dev/null +++ b/src/mbgl/shaders/vulkan/fill_extrusion.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +namespace mbgl { +namespace shaders { + +// +// Fill extrusion + +using FillExtrusionShaderSource = ShaderSource; + +const std::array FillExtrusionShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, +}; +const std::array FillExtrusionShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Float4, idFillExtrusionColorVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, +}; +const std::array FillExtrusionShaderSource::textures = {}; + +// +// Fill extrusion pattern + +using FillExtrusionPatternShaderSource = ShaderSource; + +const std::array FillExtrusionPatternShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, +}; +const std::array FillExtrusionPatternShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, + AttributeInfo{5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, +}; +const std::array FillExtrusionPatternShaderSource::textures = { + TextureInfo{0, idFillExtrusionImageTexture}, +}; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/heatmap.cpp b/src/mbgl/shaders/vulkan/heatmap.cpp index 12c6a41c684..69688327c6b 100644 --- a/src/mbgl/shaders/vulkan/heatmap.cpp +++ b/src/mbgl/shaders/vulkan/heatmap.cpp @@ -1,35 +1,22 @@ #include #include #include -#include namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using HeatmapShaderSource = ShaderSource; + +const std::array HeatmapShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(HeatmapDrawableUBO), idHeatmapDrawableUBO}, - UniformBlockInfo{true, false, sizeof(HeatmapInterpolateUBO), idHeatmapInterpolateUBO}, UniformBlockInfo{true, true, sizeof(HeatmapEvaluatedPropsUBO), idHeatmapEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array HeatmapShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float2, idHeatmapWeightVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float2, idHeatmapRadiusVertexAttribute}, }; - -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, -}; -const std::array ShaderSource::attributes = - { - AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idHeatmapImageTexture}, - TextureInfo{1, idHeatmapColorRampTexture}, -}; +const std::array HeatmapShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/heatmap_texture.cpp b/src/mbgl/shaders/vulkan/heatmap_texture.cpp new file mode 100644 index 00000000000..6b64bb891d0 --- /dev/null +++ b/src/mbgl/shaders/vulkan/heatmap_texture.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +namespace mbgl { +namespace shaders { + +using HeatmapTextureShaderSource = ShaderSource; + +const std::array HeatmapTextureShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, +}; +const std::array HeatmapTextureShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, +}; +const std::array HeatmapTextureShaderSource::textures = { + TextureInfo{0, idHeatmapImageTexture}, + TextureInfo{1, idHeatmapColorRampTexture}, +}; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/hillshade.cpp b/src/mbgl/shaders/vulkan/hillshade.cpp index 50dd92d0de2..fa85290bdb4 100644 --- a/src/mbgl/shaders/vulkan/hillshade.cpp +++ b/src/mbgl/shaders/vulkan/hillshade.cpp @@ -1,33 +1,22 @@ #include #include #include -#include namespace mbgl { namespace shaders { -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, -}; -const std::array - ShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idHillshadeImageTexture}, -}; +using HillshadeShaderSource = ShaderSource; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, +const std::array HillshadeShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, + UniformBlockInfo{false, true, sizeof(HillshadeTilePropsUBO), idHillshadeTilePropsUBO}, UniformBlockInfo{false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array HillshadeShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array HillshadeShaderSource::textures = { TextureInfo{0, idHillshadeImageTexture}, }; diff --git a/src/mbgl/shaders/vulkan/hillshade_prepare.cpp b/src/mbgl/shaders/vulkan/hillshade_prepare.cpp new file mode 100644 index 00000000000..777aee07034 --- /dev/null +++ b/src/mbgl/shaders/vulkan/hillshade_prepare.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +namespace mbgl { +namespace shaders { + +using HillshadePrepareShaderSource = ShaderSource; + +const std::array HillshadePrepareShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, + UniformBlockInfo{true, true, sizeof(HillshadePrepareTilePropsUBO), idHillshadePrepareTilePropsUBO}, +}; +const std::array HillshadePrepareShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, +}; +const std::array HillshadePrepareShaderSource::textures = { + TextureInfo{0, idHillshadeImageTexture}, +}; +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/line.cpp b/src/mbgl/shaders/vulkan/line.cpp index a40c38de3b1..607b3e164a8 100644 --- a/src/mbgl/shaders/vulkan/line.cpp +++ b/src/mbgl/shaders/vulkan/line.cpp @@ -5,14 +5,17 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, +// +// Line + +using LineShaderSource = ShaderSource; + +const std::array LineShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(LineDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, false, sizeof(LineInterpolationUBO), idLineInterpolationUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, }; - -const std::array ShaderSource::attributes = { +const std::array LineShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, @@ -22,16 +25,19 @@ const std::array ShaderSource LineShaderSource::textures = {}; -const std::array ShaderSource::uniforms = - { - UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LineDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, false, sizeof(LineInterpolationUBO), idLineInterpolationUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, -}; +// +// Line gradient + +using LineGradientShaderSource = ShaderSource; -const std::array ShaderSource::attributes = { +const std::array LineGradientShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(LineGradientDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, +}; +const std::array LineGradientShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, @@ -40,19 +46,22 @@ const std::array ShaderSource ShaderSource::textures = { +const std::array LineGradientShaderSource::textures = { TextureInfo{0, idLineImageTexture}, }; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(LinePatternDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, false, sizeof(LinePatternInterpolationUBO), idLineInterpolationUBO}, - UniformBlockInfo{true, true, sizeof(LinePatternTilePropertiesUBO), idLineTilePropertiesUBO}, +// +// Line pattern + +using LinePatternShaderSource = ShaderSource; + +const std::array LinePatternShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(LinePatternDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{false, true, sizeof(LinePatternTilePropsUBO), idLineTilePropsUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array LinePatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float2, idLineBlurVertexAttribute}, @@ -63,17 +72,22 @@ const std::array ShaderSource ShaderSource::textures = { +const std::array LinePatternShaderSource::textures = { TextureInfo{0, idLineImageTexture}, }; -const std::array ShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(LineSDFDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, false, sizeof(LineSDFInterpolationUBO), idLineInterpolationUBO}, +// +// Line SDF + +using LineSDFShaderSource = ShaderSource; + +const std::array LineSDFShaderSource::uniforms = { + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(LineSDFDrawableUBO), idLineDrawableUBO}, + UniformBlockInfo{false, true, sizeof(LineSDFTilePropsUBO), idLineTilePropsUBO}, UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array LineSDFShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float4, idLineColorVertexAttribute}, @@ -84,7 +98,7 @@ const std::array ShaderSource ShaderSource::textures = { +const std::array LineSDFShaderSource::textures = { TextureInfo{0, idLineImageTexture}, }; diff --git a/src/mbgl/shaders/vulkan/location_indicator.cpp b/src/mbgl/shaders/vulkan/location_indicator.cpp new file mode 100644 index 00000000000..3275153ce27 --- /dev/null +++ b/src/mbgl/shaders/vulkan/location_indicator.cpp @@ -0,0 +1,38 @@ +#include +#include +#include + +namespace mbgl { +namespace shaders { + +// +// Location indicator + +using LocationIndicatorShaderSource = ShaderSource; + +const std::array LocationIndicatorShaderSource::uniforms = { + UniformBlockInfo{true, true, sizeof(LocationIndicatorDrawableUBO), idLocationIndicatorDrawableUBO}, +}; +const std::array LocationIndicatorShaderSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute}, +}; +const std::array LocationIndicatorShaderSource::textures = {}; + +// +// Location indicator textured + +using LocationIndicatorShaderTexturedSource = ShaderSource; + +const std::array LocationIndicatorShaderTexturedSource::uniforms = { + UniformBlockInfo{true, false, sizeof(LocationIndicatorDrawableUBO), idLocationIndicatorDrawableUBO}, +}; +const std::array LocationIndicatorShaderTexturedSource::attributes = { + AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Float2, idCommonTexVertexAttribute}, +}; +const std::array LocationIndicatorShaderTexturedSource::textures = { + TextureInfo{0, idCommonTexture}, +}; + +} // namespace shaders +} // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/raster.cpp b/src/mbgl/shaders/vulkan/raster.cpp index cab5e36b021..177c3579d7b 100644 --- a/src/mbgl/shaders/vulkan/raster.cpp +++ b/src/mbgl/shaders/vulkan/raster.cpp @@ -5,15 +5,17 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using RasterShaderSource = ShaderSource; + +const std::array RasterShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(RasterDrawableUBO), idRasterDrawableUBO}, UniformBlockInfo{true, true, sizeof(RasterEvaluatedPropsUBO), idRasterEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array RasterShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idRasterPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idRasterTexturePosVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array RasterShaderSource::textures = { TextureInfo{0, idRasterImage0Texture}, TextureInfo{1, idRasterImage1Texture}, }; diff --git a/src/mbgl/shaders/vulkan/symbol.cpp b/src/mbgl/shaders/vulkan/symbol.cpp index 3172f86aaa8..3bcab1cd451 100644 --- a/src/mbgl/shaders/vulkan/symbol.cpp +++ b/src/mbgl/shaders/vulkan/symbol.cpp @@ -1,100 +1,94 @@ #include #include #include -#include namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +// +// Symbol icon + +using SymbolIconShaderSource = ShaderSource; + +const std::array SymbolIconShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = { +const std::array SymbolIconShaderSource::attributes = { + // always attributes AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, AttributeInfo{3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, AttributeInfo{4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + + // sometimes uniforms AttributeInfo{5, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array SymbolIconShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, }; -const std::array ShaderSource::uniforms = - { +// +// Symbol sdf + +using SymbolSDFIconShaderSource = ShaderSource; + +const std::array SymbolSDFIconShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, }; -const std::array ShaderSource::attributes = - { +const std::array SymbolSDFIconShaderSource::attributes = { // always attributes AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, AttributeInfo{3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float2, idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, // sometimes uniforms AttributeInfo{5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, AttributeInfo{6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float2, idSymbolOpacityVertexAttribute}, - AttributeInfo{8, gfx::AttributeDataType::Float2, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{9, gfx::AttributeDataType::Float2, idSymbolHaloBlurVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, }; -const std::array ShaderSource::textures = { +const std::array SymbolSDFIconShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, }; -const std::array - ShaderSource::uniforms = { +// +// Symbol icon and text + +using SymbolTextAndIconShaderSource = ShaderSource; + +const std::array SymbolTextAndIconShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{true, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolInterpolateUBO), idSymbolInterpolateUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, }; -const std::array - ShaderSource::attributes = { +const std::array SymbolTextAndIconShaderSource::attributes = { // always attributes AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, AttributeInfo{2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, // sometimes uniforms AttributeInfo{4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, AttributeInfo{5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float2, idSymbolOpacityVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float2, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{8, gfx::AttributeDataType::Float2, idSymbolHaloBlurVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, }; -const std::array ShaderSource::textures = - { - TextureInfo{0, idSymbolImageTexture}, - TextureInfo{1, idSymbolImageIconTexture}, -}; - -const std::array - ShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, - UniformBlockInfo{true, false, sizeof(CustomSymbolIconParametersUBO), idCustomSymbolParametersUBO}, -}; -const std::array - ShaderSource::attributes = { - // always attributes - AttributeInfo{0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, -}; -const std::array ShaderSource::textures = { - TextureInfo{0, idCustomSymbolImageTexture}, +const std::array SymbolTextAndIconShaderSource::textures = { + TextureInfo{0, idSymbolImageTexture}, + TextureInfo{1, idSymbolImageIconTexture}, }; } // namespace shaders diff --git a/src/mbgl/shaders/vulkan/widevector.cpp b/src/mbgl/shaders/vulkan/widevector.cpp index a140b185881..d1200ab88fd 100644 --- a/src/mbgl/shaders/vulkan/widevector.cpp +++ b/src/mbgl/shaders/vulkan/widevector.cpp @@ -5,20 +5,24 @@ namespace mbgl { namespace shaders { -const std::array ShaderSource::uniforms = { +using WideVectorShaderSource = ShaderSource; + +const std::array WideVectorShaderSource::uniforms = { UniformBlockInfo{true, false, sizeof(WideVectorUniformsUBO), idWideVectorUniformsUBO}, UniformBlockInfo{true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO}, }; -const std::array ShaderSource::attributes = { +const std::array WideVectorShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float3, idWideVectorScreenPos}, AttributeInfo{1, gfx::AttributeDataType::Float4, idWideVectorColor}, - AttributeInfo{2, gfx::AttributeDataType::Int, idWideVectorIndex}}; -const std::array - ShaderSource::instanceAttributes = { - AttributeInfo{3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter}, - AttributeInfo{4, gfx::AttributeDataType::Float4, idWideVectorInstanceColor}, - AttributeInfo{5, gfx::AttributeDataType::Int, idWideVectorInstancePrevious}, - AttributeInfo{6, gfx::AttributeDataType::Int, idWideVectorInstanceNext}}; + AttributeInfo{2, gfx::AttributeDataType::Int, idWideVectorIndex}, +}; +const std::array WideVectorShaderSource::instanceAttributes = { + AttributeInfo{3, gfx::AttributeDataType::Float3, idWideVectorInstanceCenter}, + AttributeInfo{4, gfx::AttributeDataType::Float4, idWideVectorInstanceColor}, + AttributeInfo{5, gfx::AttributeDataType::Int, idWideVectorInstancePrevious}, + AttributeInfo{6, gfx::AttributeDataType::Int, idWideVectorInstanceNext}, +}; +const std::array WideVectorShaderSource::textures = {}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index 8a1e66b4581..c7b91dc697f 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -108,23 +108,21 @@ class LineDrawableTweaker : public gfx::DrawableTweaker { const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::LineDrawableUBO drawableUBO = {/*matrix = */ util::cast(matrix), - /*ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - 0, - 0, - 0}; - const shaders::LineInterpolationUBO lineInterpolationUBO{/*color_t =*/0.f, - /*blur_t =*/0.f, - /*opacity_t =*/0.f, - /*gapwidth_t =*/0.f, - /*offset_t =*/0.f, - /*width_t =*/0.f, - 0, - 0}; + const shaders::LineDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), + + /* .color_t = */ 0.f, + /* .blur_t = */ 0.f, + /* .opacity_t = */ 0.f, + /* .gapwidth_t = */ 0.f, + /* .offset_t = */ 0.f, + /* .width_t = */ 0.f, + /* .pad1 = */ 0 + }; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); - drawableUniforms.createOrUpdate(idLineInterpolationUBO, &lineInterpolationUBO, parameters.context); - drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context, true, false); + drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); @@ -164,33 +162,37 @@ class WideVectorDrawableTweaker : public gfx::DrawableTweaker { matrix::diffsplit(pMatrix, pMatrixDiff, projMatrix); const auto renderableSize = parameters.backend.getDefaultRenderable().getSize(); - shaders::WideVectorUniformsUBO uniform{ - /*mvpMatrix */ mvpMatrix, - /*mvpMatrixDiff */ mvpMatrixDiff, - /*mvMatrix */ mvMatrix, - /*mvMatrixDiff */ mvMatrixDiff, - /*pMatrix */ pMatrix, - /*pMatrixDiff */ pMatrixDiff, - /*frameSize */ {(float)renderableSize.width, (float)renderableSize.height}}; - - shaders::WideVectorUniformWideVecUBO wideVec{ - /*color */ options.color, - /*w2 */ options.width, - /*offset */ options.offset, - /*edge */ 0.0f, // TODO: MLN does not provide a value. Analyze impact. - /*texRepeat */ 0.0f, // N/A - /*texOffset */ {}, // N/A - /*miterLimit */ options.geometry.miterLimit, - /*join */ static_cast(options.geometry.joinType), - /*cap */ static_cast(options.geometry.beginCap), // TODO: MLN option for endCap to be - // implemented in the shader! - /*hasExp */ false, // N/A - /*interClipLimit*/ 0.0f // N/A + shaders::WideVectorUniformsUBO uniform = { + /* .mvpMatrix = */ mvpMatrix, + /* .mvpMatrixDiff = */ mvpMatrixDiff, + /* .mvMatrix = */ mvMatrix, + /* .mvMatrixDiff = */ mvMatrixDiff, + /* .pMatrix = */ pMatrix, + /* .pMatrixDiff = */ pMatrixDiff, + /* .frameSize = */ {(float)renderableSize.width, (float)renderableSize.height}, + /* .pad1 = */ 0, + /* .pad2 = */ 0 + }; + + shaders::WideVectorUniformWideVecUBO wideVec = { + /* .color = */ options.color, + /* .w2 = */ options.width, + /* .offset = */ options.offset, + /* .edge = */ 0.0f, // TODO: MLN does not provide a value. Analyze impact. + /* .texRepeat = */ 0.0f, // N/A + /* .texOffset = */ {}, // N/A + /* .miterLimit = */ options.geometry.miterLimit, + /* .join = */ static_cast(options.geometry.joinType), + /* .cap = */ static_cast(options.geometry.beginCap), // TODO: MLN option for endCap to be + // implemented in the shader! + /* .hasExp = */ false, // N/A + /* .interClipLimit = */ 0.0f, // N/A + /* .pad1 = */ 0 }; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idWideVectorUniformsUBO, &uniform, parameters.context); - drawableUniforms.createOrUpdate(idWideVectorUniformWideVecUBO, &wideVec, parameters.context); + drawableUniforms.createOrUpdate(idWideVectorUniformsUBO, &uniform, parameters.context, true, false); + drawableUniforms.createOrUpdate(idWideVectorUniformWideVecUBO, &wideVec, parameters.context, true, false); }; private: @@ -218,26 +220,26 @@ class FillDrawableTweaker : public gfx::DrawableTweaker { const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::FillDrawableUBO fillDrawableUBO{/*matrix = */ util::cast(matrix)}; - - const shaders::FillInterpolateUBO fillInterpolateUBO{ + const shaders::FillDrawableUBO fillDrawableUBO = { + /* .matrix = */ util::cast(matrix), + /* .color_t = */ 0.f, /* .opacity_t = */ 0.f, - 0, - 0, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; - const shaders::FillEvaluatedPropsUBO fillPropertiesUBO{ + + const shaders::FillEvaluatedPropsUBO fillPropertiesUBO = { /* .color = */ color, /* .outline_color = */ Color::white(), /* .opacity = */ opacity, /* .fade = */ 0.f, /* .from_scale = */ 0.f, - /* .to_scale = */ 0.f, + /* .to_scale = */ 0.f }; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idFillDrawableUBO, &fillDrawableUBO, parameters.context); - drawableUniforms.createOrUpdate(idFillInterpolateUBO, &fillInterpolateUBO, parameters.context); - drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &fillDrawableUBO, parameters.context, true, false); + drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context, true, true); }; private: @@ -265,8 +267,6 @@ class SymbolDrawableTweaker : public gfx::DrawableTweaker { const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::CustomSymbolIconDrawableUBO drawableUBO{/*matrix = */ util::cast(matrix)}; - const auto pixelsToTileUnits = tileID.pixelsToTileUnits( 1.0f, options.scaleWithMap ? tileID.canonical.z : parameters.state.getZoom()); const float factor = options.scaleWithMap @@ -276,22 +276,22 @@ class SymbolDrawableTweaker : public gfx::DrawableTweaker { : std::array{parameters.pixelsToGLUnits[0] * factor, parameters.pixelsToGLUnits[1] * factor}; - const shaders::CustomSymbolIconParametersUBO parametersUBO{ - /*extrude_scale*/ {extrudeScale[0] * options.size.width, extrudeScale[1] * options.size.height}, - /*anchor*/ options.anchor, - /*angle_degrees*/ options.angleDegrees, - /*scale_with_map*/ options.scaleWithMap, - /*pitch_with_map*/ options.pitchWithMap, - /*camera_to_center_distance*/ parameters.state.getCameraToCenterDistance(), - /*aspect_ratio*/ parameters.pixelsToGLUnits[0] / parameters.pixelsToGLUnits[1], - 0, - 0, - 0}; - - // set UBOs + const shaders::CustomSymbolIconDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(matrix), + /* .extrude_scale = */ {extrudeScale[0] * options.size.width, extrudeScale[1] * options.size.height}, + /* .anchor = */ options.anchor, + /* .angle_degrees = */ options.angleDegrees, + /* .scale_with_map = */ options.scaleWithMap, + /* .pitch_with_map = */ options.pitchWithMap, + /* .camera_to_center_distance = */ parameters.state.getCameraToCenterDistance(), + /* .aspect_ratio = */ parameters.pixelsToGLUnits[0] / parameters.pixelsToGLUnits[1], + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0 + }; + auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idCustomSymbolDrawableUBO, &drawableUBO, parameters.context); - drawableUniforms.createOrUpdate(idCustomSymbolParametersUBO, ¶metersUBO, parameters.context); + drawableUniforms.createOrUpdate(idCustomSymbolDrawableUBO, &drawableUBO, parameters.context, true, false); }; private: @@ -405,6 +405,7 @@ bool CustomDrawableLayerHost::Interface::addPolyline(const GeometryCoordinates& } bool CustomDrawableLayerHost::Interface::addFill(const GeometryCollection& geometry) { + return true; // build fill if (!updateBuilder(BuilderType::Fill, "custom-fill", fillShaderDefault())) return false; diff --git a/src/mbgl/vulkan/context.cpp b/src/mbgl/vulkan/context.cpp index 9f54ebed28b..2bdca00d583 100644 --- a/src/mbgl/vulkan/context.cpp +++ b/src/mbgl/vulkan/context.cpp @@ -442,13 +442,11 @@ void Context::bindGlobalUniformBuffers(gfx::RenderPass& renderPass) const noexce if (renderableResource.hasSurfaceTransformSupport()) { float surfaceRotation = renderableResource.getRotation(); - struct alignas(16) { - alignas(16) std::array rotation0; - alignas(16) std::array rotation1; - } data; - - data = {{cosf(surfaceRotation), -sinf(surfaceRotation)}, {sinf(surfaceRotation), cosf(surfaceRotation)}}; - context.globalUniformBuffers.createOrUpdate(shaders::PlatformParamsUBO, &data, sizeof(data), context); + const shaders::GlobalPlatformParamsUBO platformUBO = { + /* .rotation0 = */ {cosf(surfaceRotation), -sinf(surfaceRotation)}, + /* .rotation1 = */ {sinf(surfaceRotation), cosf(surfaceRotation)} + }; + context.globalUniformBuffers.createOrUpdate(shaders::idGlobalPlatformParamsUBO, &platformUBO, sizeof(platformUBO), context, true, true); } context.globalUniformBuffers.bindDescriptorSets(renderPassImpl.getEncoder()); diff --git a/src/mbgl/vulkan/renderer_backend.cpp b/src/mbgl/vulkan/renderer_backend.cpp index e2b44708133..b3b67fe4e96 100644 --- a/src/mbgl/vulkan/renderer_backend.cpp +++ b/src/mbgl/vulkan/renderer_backend.cpp @@ -12,12 +12,16 @@ #include #include #include -#include +#include #include #include +#include #include +#include #include +#include #include +#include #include #include #include @@ -632,8 +636,6 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar shaders::BuiltIn::ClippingMaskProgram, shaders::BuiltIn::CollisionBoxShader, shaders::BuiltIn::CollisionCircleShader, - shaders::BuiltIn::CommonShader, - shaders::BuiltIn::CommonTexturedShader, shaders::BuiltIn::CustomSymbolIconShader, shaders::BuiltIn::DebugShader, shaders::BuiltIn::FillShader, @@ -651,6 +653,8 @@ void RendererBackend::initShaders(gfx::ShaderRegistry& shaders, const ProgramPar shaders::BuiltIn::LineGradientShader, shaders::BuiltIn::LineSDFShader, shaders::BuiltIn::LinePatternShader, + shaders::BuiltIn::LocationIndicatorShader, + shaders::BuiltIn::LocationIndicatorTexturedShader, shaders::BuiltIn::RasterShader, shaders::BuiltIn::SymbolIconShader, shaders::BuiltIn::SymbolSDFIconShader, diff --git a/src/mbgl/vulkan/uniform_buffer.cpp b/src/mbgl/vulkan/uniform_buffer.cpp index b01e0facc90..86d94af485d 100644 --- a/src/mbgl/vulkan/uniform_buffer.cpp +++ b/src/mbgl/vulkan/uniform_buffer.cpp @@ -40,7 +40,9 @@ void UniformBuffer::update(const void* data, std::size_t size_) { } const std::shared_ptr& UniformBufferArray::set(const size_t id, - std::shared_ptr uniformBuffer) { + std::shared_ptr uniformBuffer, + bool bindVertex, + bool bindFragment) { if (id >= uniformBufferVector.size()) { return nullref; } @@ -54,18 +56,22 @@ const std::shared_ptr& UniformBufferArray::set(const size_t } uniformBufferVector[id] = std::move(uniformBuffer); + if (uniformBufferVector[id]) { + uniformBufferVector[id]->setBindVertex(bindVertex); + uniformBufferVector[id]->setBindFragment(bindFragment); + } return uniformBufferVector[id]; } void UniformBufferArray::createOrUpdate( - const size_t id, const void* data, std::size_t size, gfx::Context& context, bool persistent) { + const size_t id, const void* data, std::size_t size, gfx::Context& context, bool bindVertex, bool bindFragment) { if (descriptorSet) { if (auto& ubo = get(id); !ubo || ubo->getSize() != size) { descriptorSet->markDirty(); } } - gfx::UniformBufferArray::createOrUpdate(id, data, size, context, persistent); + gfx::UniformBufferArray::createOrUpdate(id, data, size, context, bindVertex, bindFragment); } void UniformBufferArray::bindDescriptorSets(CommandEncoder& encoder) { diff --git a/test/util/hash.test.cpp b/test/util/hash.test.cpp index ce5c314b367..d2563a7f743 100644 --- a/test/util/hash.test.cpp +++ b/test/util/hash.test.cpp @@ -11,15 +11,12 @@ #if MLN_RENDER_BACKEND_METAL #include -#include #include #include -#include -#include +#include #include #include #include -#include #include #include #include @@ -27,9 +24,7 @@ #include #include #include -#include -#include -#include +#include #endif using namespace mbgl; From de9181c22eb60c5c3f46c6ae92cb3747348ff680 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:16:05 +0000 Subject: [PATCH 02/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- include/mbgl/gfx/context.hpp | 4 +- include/mbgl/gfx/uniform_buffer.hpp | 10 ++- include/mbgl/gl/uniform_buffer_gl.hpp | 2 +- include/mbgl/mtl/context.hpp | 4 +- include/mbgl/mtl/uniform_buffer.hpp | 2 +- .../mbgl/shaders/fill_extrusion_layer_ubo.hpp | 2 +- include/mbgl/shaders/fill_layer_ubo.hpp | 10 +-- include/mbgl/shaders/layer_ubo.hpp | 2 +- include/mbgl/shaders/line_layer_ubo.hpp | 8 +-- include/mbgl/shaders/mtl/background.hpp | 3 +- include/mbgl/shaders/mtl/circle.hpp | 3 +- include/mbgl/shaders/mtl/clipping_mask.hpp | 3 +- include/mbgl/shaders/mtl/collision.hpp | 7 +- .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 3 +- include/mbgl/shaders/mtl/debug.hpp | 3 +- include/mbgl/shaders/mtl/fill.hpp | 3 +- include/mbgl/shaders/mtl/fill_extrusion.hpp | 3 +- include/mbgl/shaders/mtl/heatmap.hpp | 3 +- include/mbgl/shaders/mtl/heatmap_texture.hpp | 3 +- include/mbgl/shaders/mtl/hillshade.hpp | 3 +- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 3 +- include/mbgl/shaders/mtl/line.hpp | 3 +- include/mbgl/shaders/mtl/raster.hpp | 3 +- include/mbgl/shaders/mtl/symbol.hpp | 3 +- include/mbgl/shaders/mtl/widevector.hpp | 3 +- include/mbgl/shaders/symbol_layer_ubo.hpp | 6 +- include/mbgl/vulkan/uniform_buffer.hpp | 14 ++-- src/mbgl/gfx/uniform_buffer.cpp | 13 ++-- src/mbgl/gl/uniform_buffer_gl.cpp | 4 +- src/mbgl/mtl/context.cpp | 4 +- .../layers/background_layer_tweaker.cpp | 42 +++++------ .../renderer/layers/circle_layer_tweaker.cpp | 6 +- .../renderer/layers/circle_layer_tweaker.hpp | 2 +- .../layers/collision_layer_tweaker.cpp | 9 +-- .../layers/fill_extrusion_layer_tweaker.cpp | 4 +- .../layers/fill_extrusion_layer_tweaker.hpp | 2 +- .../renderer/layers/fill_layer_tweaker.cpp | 50 +++++++------ .../renderer/layers/fill_layer_tweaker.hpp | 2 +- .../renderer/layers/heatmap_layer_tweaker.cpp | 6 +- .../renderer/layers/heatmap_layer_tweaker.hpp | 2 +- .../layers/heatmap_texture_layer_tweaker.cpp | 12 ++-- .../layers/hillshade_layer_tweaker.cpp | 10 +-- .../layers/hillshade_layer_tweaker.hpp | 2 +- .../hillshade_prepare_layer_tweaker.cpp | 7 +- .../renderer/layers/line_layer_tweaker.cpp | 55 ++++++++------- .../renderer/layers/line_layer_tweaker.hpp | 2 +- .../location_indicator_layer_tweaker.cpp | 26 ++++--- .../renderer/layers/raster_layer_tweaker.cpp | 4 +- .../renderer/layers/raster_layer_tweaker.hpp | 2 +- .../renderer/layers/symbol_layer_tweaker.cpp | 34 +++++---- src/mbgl/renderer/paint_parameters.cpp | 24 +++---- .../renderer/sources/render_tile_source.cpp | 70 ++++++++----------- src/mbgl/shaders/mtl/background.cpp | 14 ++-- src/mbgl/shaders/mtl/collision.cpp | 12 ++-- src/mbgl/shaders/mtl/custom_symbol_icon.cpp | 2 +- src/mbgl/shaders/mtl/fill.cpp | 31 ++++---- src/mbgl/shaders/mtl/fill_extrusion.cpp | 17 ++--- src/mbgl/shaders/mtl/heatmap_texture.cpp | 6 +- src/mbgl/shaders/mtl/hillshade_prepare.cpp | 4 +- src/mbgl/shaders/mtl/symbol.cpp | 62 ++++++++-------- src/mbgl/shaders/vulkan/background.cpp | 14 ++-- src/mbgl/shaders/vulkan/collision.cpp | 12 ++-- .../shaders/vulkan/custom_symbol_icon.cpp | 2 +- src/mbgl/shaders/vulkan/fill.cpp | 31 ++++---- src/mbgl/shaders/vulkan/fill_extrusion.cpp | 14 ++-- src/mbgl/shaders/vulkan/heatmap_texture.cpp | 6 +- src/mbgl/shaders/vulkan/hillshade_prepare.cpp | 4 +- .../shaders/vulkan/location_indicator.cpp | 9 +-- src/mbgl/shaders/vulkan/symbol.cpp | 62 ++++++++-------- .../style/layers/custom_drawable_layer.cpp | 65 ++++++++--------- src/mbgl/vulkan/context.cpp | 6 +- 71 files changed, 441 insertions(+), 442 deletions(-) diff --git a/include/mbgl/gfx/context.hpp b/include/mbgl/gfx/context.hpp index e2f8302d064..8e21265098f 100644 --- a/include/mbgl/gfx/context.hpp +++ b/include/mbgl/gfx/context.hpp @@ -125,9 +125,7 @@ class Context { /// @param data The data to copy, may be `nullptr` /// @param size The size of the buffer /// @param persistent Performance hint, optimize for few or many uses - virtual UniformBufferPtr createUniformBuffer(const void* data, - std::size_t size, - bool persistent = false) = 0; + virtual UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false) = 0; /// Get the generic shader with the specified name virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0; diff --git a/include/mbgl/gfx/uniform_buffer.hpp b/include/mbgl/gfx/uniform_buffer.hpp index 72ef7f0102f..c76ce7c5385 100644 --- a/include/mbgl/gfx/uniform_buffer.hpp +++ b/include/mbgl/gfx/uniform_buffer.hpp @@ -47,7 +47,7 @@ class UniformBuffer { bool getBindFragment() const { return bindFragment; } void setBindFragment(bool value) { bindFragment = value; } - + protected: std::size_t size; bool bindVertex = false; @@ -71,10 +71,14 @@ class UniformBufferArray { const std::shared_ptr& get(const size_t id) const; /// Set a new uniform buffer element or replace the existing one. - virtual const std::shared_ptr& set(const size_t id, std::shared_ptr uniformBuffer, bool bindVertex, bool bindFragment); + virtual const std::shared_ptr& set(const size_t id, + std::shared_ptr uniformBuffer, + bool bindVertex, + bool bindFragment); /// Create and add a new buffer or update an existing one - void createOrUpdate(const size_t id, const std::vector& data, gfx::Context&, bool bindVertex, bool bindFragment); + void createOrUpdate( + const size_t id, const std::vector& data, gfx::Context&, bool bindVertex, bool bindFragment); virtual void createOrUpdate( const size_t id, const void* data, std::size_t size, gfx::Context&, bool bindVertex, bool bindFragment); template diff --git a/include/mbgl/gl/uniform_buffer_gl.hpp b/include/mbgl/gl/uniform_buffer_gl.hpp index 5d1361a6a5d..770c5c4bb61 100644 --- a/include/mbgl/gl/uniform_buffer_gl.hpp +++ b/include/mbgl/gl/uniform_buffer_gl.hpp @@ -58,7 +58,7 @@ class UniformBufferArrayGL final : public gfx::UniformBufferArray { UniformBufferArray::operator=(other); return *this; } - + void bind() const; void unbind() const; diff --git a/include/mbgl/mtl/context.hpp b/include/mbgl/mtl/context.hpp index f1c9e7e5130..6934ced790f 100644 --- a/include/mbgl/mtl/context.hpp +++ b/include/mbgl/mtl/context.hpp @@ -83,9 +83,7 @@ class Context final : public gfx::Context { void reduceMemoryUsage() override {} gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override; - gfx::UniformBufferPtr createUniformBuffer(const void* data, - std::size_t size, - bool persisten) override; + gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persisten) override; gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override; diff --git a/include/mbgl/mtl/uniform_buffer.hpp b/include/mbgl/mtl/uniform_buffer.hpp index fdfbb31ff5b..399f122b706 100644 --- a/include/mbgl/mtl/uniform_buffer.hpp +++ b/include/mbgl/mtl/uniform_buffer.hpp @@ -44,7 +44,7 @@ class UniformBufferArray final : public gfx::UniformBufferArray { void bind(RenderPass& renderPass) const noexcept; void unbind(RenderPass& renderPass) const noexcept {}; - + private: gfx::UniqueUniformBuffer copy(const gfx::UniformBuffer& buffer) override { return std::make_unique(static_cast(buffer).clone()); diff --git a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp index 8213ea077b2..a87eddc0dde 100644 --- a/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_extrusion_layer_ubo.hpp @@ -13,7 +13,7 @@ struct alignas(16) FillExtrusionDrawableUBO { /* 72 */ std::array pixel_coord_lower; /* 80 */ float height_factor; /* 84 */ float tile_ratio; - + // Interpolations /* 88 */ float base_t; /* 92 */ float height_t; diff --git a/include/mbgl/shaders/fill_layer_ubo.hpp b/include/mbgl/shaders/fill_layer_ubo.hpp index dc434be19fe..959c1aa1067 100644 --- a/include/mbgl/shaders/fill_layer_ubo.hpp +++ b/include/mbgl/shaders/fill_layer_ubo.hpp @@ -10,7 +10,7 @@ namespace shaders { struct alignas(16) FillDrawableUBO { /* 0 */ std::array matrix; - + // Interpolations /* 64 */ float color_t; /* 68 */ float opacity_t; @@ -25,7 +25,7 @@ static_assert(sizeof(FillDrawableUBO) == 5 * 16); struct alignas(16) FillOutlineDrawableUBO { /* 0 */ std::array matrix; - + // Interpolations /* 64 */ float outline_color_t; /* 68 */ float opacity_t; @@ -43,7 +43,7 @@ struct alignas(16) FillPatternDrawableUBO { /* 64 */ std::array pixel_coord_upper; /* 72 */ std::array pixel_coord_lower; /* 80 */ float tile_ratio; - + // Interpolations /* 84 */ float pattern_from_t; /* 88 */ float pattern_to_t; @@ -70,7 +70,7 @@ struct alignas(16) FillOutlinePatternDrawableUBO { /* 64 */ std::array pixel_coord_upper; /* 72 */ std::array pixel_coord_lower; /* 80 */ float tile_ratio; - + // Interpolations /* 84 */ float pattern_from_t; /* 88 */ float pattern_to_t; @@ -110,7 +110,7 @@ struct alignas(16) FillEvaluatedPropsUBO { /* 36 */ float fade; /* 40 */ float from_scale; /* 44 */ float to_scale; - /* 48 */ + /* 48 */ }; static_assert(sizeof(FillEvaluatedPropsUBO) == 3 * 16); diff --git a/include/mbgl/shaders/layer_ubo.hpp b/include/mbgl/shaders/layer_ubo.hpp index a1704d533ec..3cbd0d09396 100644 --- a/include/mbgl/shaders/layer_ubo.hpp +++ b/include/mbgl/shaders/layer_ubo.hpp @@ -69,7 +69,7 @@ enum { globalUBOCount, }; -#define MLN_UBO_CONSOLIDATION MLN_RENDER_BACKEND_METAL +#define MLN_UBO_CONSOLIDATION MLN_RENDER_BACKEND_METAL } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/line_layer_ubo.hpp b/include/mbgl/shaders/line_layer_ubo.hpp index f685be9059d..34a713f40ab 100644 --- a/include/mbgl/shaders/line_layer_ubo.hpp +++ b/include/mbgl/shaders/line_layer_ubo.hpp @@ -17,7 +17,7 @@ namespace shaders { struct alignas(16) LineDrawableUBO { /* 0 */ std::array matrix; /* 64 */ float ratio; - + // Interpolations /* 68 */ float color_t; /* 72 */ float blur_t; @@ -36,7 +36,7 @@ static_assert(sizeof(LineDrawableUBO) == 6 * 16); struct alignas(16) LineGradientDrawableUBO { /* 0 */ std::array matrix; /* 64 */ float ratio; - + // Interpolations /* 68 */ float blur_t; /* 72 */ float opacity_t; @@ -55,7 +55,7 @@ static_assert(sizeof(LineGradientDrawableUBO) == 6 * 16); struct alignas(16) LinePatternDrawableUBO { /* 0 */ std::array matrix; /* 64 */ float ratio; - + // Interpolations /* 68 */ float blur_t; /* 72 */ float opacity_t; @@ -89,7 +89,7 @@ struct alignas(16) LineSDFDrawableUBO { /* 80 */ float tex_y_a; /* 84 */ float tex_y_b; /* 88 */ float ratio; - + // Interpolations /* 92 */ float color_t; /* 96 */ float blur_t; diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index ec1b11899b1..16234c5c985 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define BACKGROUND_SHADER_COMMON R"( +#define BACKGROUND_SHADER_COMMON \ + R"( // // Background diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index ed4efba8bac..fa10a2ef79b 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define CIRCLE_SHADER_PRELUDE R"( +#define CIRCLE_SHADER_PRELUDE \ + R"( struct alignas(16) CircleDrawableUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index a740eecfade..4899d302ec8 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -16,7 +16,8 @@ struct alignas(16) ClipUBO { }; static_assert(sizeof(ClipUBO) == 5 * 16); -#define CLIPPING_MASK_SHADER_PRELUDE R"( +#define CLIPPING_MASK_SHADER_PRELUDE \ + R"( #include using namespace metal; diff --git a/include/mbgl/shaders/mtl/collision.hpp b/include/mbgl/shaders/mtl/collision.hpp index 1121cae3402..a9e019067b9 100644 --- a/include/mbgl/shaders/mtl/collision.hpp +++ b/include/mbgl/shaders/mtl/collision.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define COLLISION_SHADER_COMMON R"( +#define COLLISION_SHADER_COMMON \ + R"( struct alignas(16) CollisionDrawableUBO { /* 0 */ float4x4 matrix; @@ -110,12 +111,12 @@ struct ShaderSource { static constexpr auto name = "CollisionCircleShader"; static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - + static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - + static constexpr auto source = COLLISION_SHADER_COMMON R"( struct VertexStage { diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index 5f919e3dd28..96c1a47c772 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"( +#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \ + R"( struct alignas(16) CustomSymbolIconDrawableUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index 498188765cc..711da492339 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define DEBUG_SHADER_PRELUDE R"( +#define DEBUG_SHADER_PRELUDE \ + R"( struct alignas(16) DebugUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index 37d7c88d7be..de0bfd720ae 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define FILL_SHADER_COMMON R"( +#define FILL_SHADER_COMMON \ + R"( // // Fill diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index d1746d23de0..e651d9842d2 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define FILL_EXTRUSION_SHADER_COMMON R"( +#define FILL_EXTRUSION_SHADER_COMMON \ + R"( struct alignas(16) FillExtrusionDrawableUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/heatmap.hpp b/include/mbgl/shaders/mtl/heatmap.hpp index 1d0a3fa8034..3b8caf6fa8c 100644 --- a/include/mbgl/shaders/mtl/heatmap.hpp +++ b/include/mbgl/shaders/mtl/heatmap.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define HEATMAP_SHADER_PRELUDE R"( +#define HEATMAP_SHADER_PRELUDE \ + R"( struct alignas(16) HeatmapDrawableUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index 6745492e102..af3686eb344 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define HEATMAP_TEXTURE_SHADER_PRELUDE R"( +#define HEATMAP_TEXTURE_SHADER_PRELUDE \ + R"( struct alignas(16) HeatmapTexturePropsUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index 35005696673..34748b8de5d 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define HILLSHADE_SHADER_PRELUDE R"( +#define HILLSHADE_SHADER_PRELUDE \ + R"( struct alignas(16) HillshadeDrawableUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index b2c0b7522da..7b3d8e41bde 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define HILLSHADE_PREPARE_SHADER_PRELUDE R"( +#define HILLSHADE_PREPARE_SHADER_PRELUDE \ + R"( struct alignas(16) HillshadePrepareDrawableUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index f771a2caf05..5fb35d3aafe 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define LINE_SHADER_COMMON R"( +#define LINE_SHADER_COMMON \ + R"( // // Line diff --git a/include/mbgl/shaders/mtl/raster.hpp b/include/mbgl/shaders/mtl/raster.hpp index f8d13174ed7..c16a548e177 100644 --- a/include/mbgl/shaders/mtl/raster.hpp +++ b/include/mbgl/shaders/mtl/raster.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define RASTER_SHADER_PRELUDE R"( +#define RASTER_SHADER_PRELUDE \ + R"( struct alignas(16) RasterDrawableUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/symbol.hpp b/include/mbgl/shaders/mtl/symbol.hpp index e9db304715f..9aa0a0fa780 100644 --- a/include/mbgl/shaders/mtl/symbol.hpp +++ b/include/mbgl/shaders/mtl/symbol.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define SYMBOL_SHADER_COMMON R"( +#define SYMBOL_SHADER_COMMON \ + R"( struct alignas(16) SymbolDrawableUBO { /* 0 */ float4x4 matrix; diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index d984a2c7326..200171ff53e 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -7,7 +7,8 @@ namespace mbgl { namespace shaders { -#define WIDEVECTOR_SHADER_PRELUDE R"( +#define WIDEVECTOR_SHADER_PRELUDE \ + R"( enum { idWideVectorUniformsUBO = globalUBOCount, diff --git a/include/mbgl/shaders/symbol_layer_ubo.hpp b/include/mbgl/shaders/symbol_layer_ubo.hpp index 6ede60798d5..84f176d0dc6 100644 --- a/include/mbgl/shaders/symbol_layer_ubo.hpp +++ b/include/mbgl/shaders/symbol_layer_ubo.hpp @@ -12,16 +12,16 @@ struct alignas(16) SymbolDrawableUBO { /* 192 */ std::array texsize; /* 200 */ std::array texsize_icon; - + /* 208 */ /*bool*/ int is_text_prop; /* 212 */ /*bool*/ int rotate_symbol; /* 216 */ /*bool*/ int pitch_with_map; /* 220 */ /*bool*/ int is_size_zoom_constant; /* 224 */ /*bool*/ int is_size_feature_constant; - + /* 228 */ float size_t; /* 232 */ float size; - + // Interpolations /* 236 */ float fill_color_t; /* 240 */ float halo_color_t; diff --git a/include/mbgl/vulkan/uniform_buffer.hpp b/include/mbgl/vulkan/uniform_buffer.hpp index 4b9b0ebf64c..039ea932b3d 100644 --- a/include/mbgl/vulkan/uniform_buffer.hpp +++ b/include/mbgl/vulkan/uniform_buffer.hpp @@ -51,10 +51,16 @@ class UniformBufferArray final : public gfx::UniformBufferArray { ~UniformBufferArray() = default; const std::shared_ptr& set(const size_t id, - std::shared_ptr uniformBuffer, bool bindVertex, bool bindFragment) override; - - void createOrUpdate( - const size_t id, const void* data, std::size_t size, gfx::Context& context, bool bindVertex, bool bindFragment) override; + std::shared_ptr uniformBuffer, + bool bindVertex, + bool bindFragment) override; + + void createOrUpdate(const size_t id, + const void* data, + std::size_t size, + gfx::Context& context, + bool bindVertex, + bool bindFragment) override; void bindDescriptorSets(CommandEncoder& encoder); void freeDescriptorSets() { descriptorSet.reset(); } diff --git a/src/mbgl/gfx/uniform_buffer.cpp b/src/mbgl/gfx/uniform_buffer.cpp index 4ec8a2557d5..b1ba94cff71 100644 --- a/src/mbgl/gfx/uniform_buffer.cpp +++ b/src/mbgl/gfx/uniform_buffer.cpp @@ -42,16 +42,17 @@ const std::shared_ptr& UniformBufferArray::set(const size_t id, return uniformBufferVector[id]; } +void UniformBufferArray::createOrUpdate( + const size_t id, const std::vector& data, gfx::Context& context, bool bindVertex, bool bindFragment) { + createOrUpdate(id, data.data(), data.size(), context, bindVertex, bindFragment); +} + void UniformBufferArray::createOrUpdate(const size_t id, - const std::vector& data, + const void* data, + const std::size_t size, gfx::Context& context, bool bindVertex, bool bindFragment) { - createOrUpdate(id, data.data(), data.size(), context, bindVertex, bindFragment); -} - -void UniformBufferArray::createOrUpdate( - const size_t id, const void* data, const std::size_t size, gfx::Context& context, bool bindVertex, bool bindFragment) { if (auto& ubo = get(id); ubo && ubo->getSize() == size) { ubo->update(data, size); } else { diff --git a/src/mbgl/gl/uniform_buffer_gl.cpp b/src/mbgl/gl/uniform_buffer_gl.cpp index dd60a3b8e8d..c1b1814b55b 100644 --- a/src/mbgl/gl/uniform_buffer_gl.cpp +++ b/src/mbgl/gl/uniform_buffer_gl.cpp @@ -127,7 +127,7 @@ void UniformBufferGL::update(const void* data_, std::size_t size_) { void UniformBufferArrayGL::bind() const { MLN_TRACE_FUNC(); - + for (size_t id = 0; id < allocatedSize(); id++) { const auto& uniformBuffer = get(id); if (!uniformBuffer) continue; @@ -143,7 +143,7 @@ void UniformBufferArrayGL::bind() const { void UniformBufferArrayGL::unbind() const { MLN_TRACE_FUNC(); - + for (size_t id = 0; id < allocatedSize(); id++) { const auto& uniformBuffer = get(id); if (!uniformBuffer) continue; diff --git a/src/mbgl/mtl/context.cpp b/src/mbgl/mtl/context.cpp index fddee302542..0842ea50f56 100644 --- a/src/mbgl/mtl/context.cpp +++ b/src/mbgl/mtl/context.cpp @@ -199,9 +199,7 @@ gfx::UniqueDrawableBuilder Context::createDrawableBuilder(std::string name) { return std::make_unique(std::move(name)); } -gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, - std::size_t size, - bool persistent) { +gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool persistent) { return std::make_shared( createBuffer(data, size, gfx::BufferUsageType::StaticDraw, /*isIndexBuffer=*/false, persistent)); } diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index 4552977ba33..a513c65086d 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -53,27 +53,23 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara auto& layerUniforms = layerGroup.mutableUniformBuffers(); if (hasPattern) { - const BackgroundPatternPropsUBO propsUBO = { - /* .pattern_tl_a = */ util::cast(imagePosA->tl()), - /* .pattern_br_a = */ util::cast(imagePosA->br()), - /* .pattern_tl_b = */ util::cast(imagePosB->tl()), - /* .pattern_br_b = */ util::cast(imagePosB->br()), - /* .pattern_size_a = */ imagePosA->displaySize(), - /* .pattern_size_b = */ imagePosB->displaySize(), - /* .scale_a = */ crossfade.fromScale, - /* .scale_b = */ crossfade.toScale, - /* .mix = */ crossfade.t, - /* .opacity = */ evaluated.get() - }; + const BackgroundPatternPropsUBO propsUBO = {/* .pattern_tl_a = */ util::cast(imagePosA->tl()), + /* .pattern_br_a = */ util::cast(imagePosA->br()), + /* .pattern_tl_b = */ util::cast(imagePosB->tl()), + /* .pattern_br_b = */ util::cast(imagePosB->br()), + /* .pattern_size_a = */ imagePosA->displaySize(), + /* .pattern_size_b = */ imagePosB->displaySize(), + /* .scale_a = */ crossfade.fromScale, + /* .scale_b = */ crossfade.toScale, + /* .mix = */ crossfade.t, + /* .opacity = */ evaluated.get()}; layerUniforms.createOrUpdate(idBackgroundPropsUBO, &propsUBO, context, true, true); } else { - const BackgroundPropsUBO propsUBO = { - /* .color = */ evaluated.get(), - /* .opacity = */ evaluated.get(), - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0 - }; + const BackgroundPropsUBO propsUBO = {/* .color = */ evaluated.get(), + /* .opacity = */ evaluated.get(), + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}; layerUniforms.createOrUpdate(idBackgroundPropsUBO, &propsUBO, context, false, true); } @@ -81,7 +77,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara int i = 0; std::vector drawableUBOVector(layerGroup.getDrawableCount()); #endif - + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { assert(drawable.getTileID()); if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -129,7 +125,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context, true, false); #endif } else { - + #if MLN_UBO_CONSOLIDATION drawableUBOVector[i].backgroundDrawableUBO = { #else @@ -141,12 +137,12 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context, true, false); #endif } - + #if MLN_UBO_CONSOLIDATION drawable.setUBOIndex(i++); #endif }); - + #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(BackgroundDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index a4f33675aff..fdb86b06f8d 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -62,7 +62,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete int i = 0; std::vector drawableUBOVector(layerGroup.getDrawableCount()); #endif - + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { assert(drawable.getTileID() || !"Circles only render with tiles"); if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -92,7 +92,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete #else const CircleDrawableUBO drawableUBO = { #endif - + /* .matrix = */ util::cast(matrix), /* .extrude_scale = */ extrudeScale, @@ -114,7 +114,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete drawableUniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context, true, false); #endif }); - + #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(CircleDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.hpp b/src/mbgl/renderer/layers/circle_layer_tweaker.hpp index 70208e0f324..944bb716b4f 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.hpp @@ -20,7 +20,7 @@ class CircleLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; - + #if MLN_UBO_CONSOLIDATION gfx::UniformBufferPtr drawableUniformBuffer; #endif diff --git a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp index 4b0fa93fe84..fd50d4723de 100644 --- a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp @@ -58,15 +58,12 @@ void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const std::array extrudeScale = {{parameters.pixelsToGLUnits[0] / (pixelRatio * scale), parameters.pixelsToGLUnits[1] / (pixelRatio * scale)}}; - const CollisionDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(matrix) - }; - + const CollisionDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix)}; + const CollisionTilePropsUBO tilePropsUBO = { /* .extrude_scale = */ extrudeScale, /* .overscale_factor = */ static_cast(drawable.getTileID()->overscaleFactor()), - /* .pad1 = */ 0 - }; + /* .pad1 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idCollisionDrawableUBO, &drawableUBO, context, true, false); diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index 9f6591308ad..50295570b89 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -69,7 +69,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP std::vector drawableUBOVector(layerGroup.getDrawableCount()); std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); #endif - + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { return; @@ -151,7 +151,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP drawableUniforms.createOrUpdate(idFillExtrusionTilePropsUBO, &tilePropsUBO, context, true, true); #endif }); - + #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(FillExtrusionDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp index 8a0393553f4..bfac229c8c2 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.hpp @@ -21,7 +21,7 @@ class FillExtrusionLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; - + #if MLN_UBO_CONSOLIDATION gfx::UniformBufferPtr drawableUniformBuffer; gfx::UniformBufferPtr tilePropsUniformBuffer; diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 924406473ac..1f3a35bb332 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -62,7 +62,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters std::vector drawableUBOVector(layerGroup.getDrawableCount()); std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); #endif - + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { return; @@ -111,13 +111,13 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const FillDrawableUBO drawableUBO = { #endif /* .matrix = */ util::cast(matrix), - + /* .color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .pad1 = */ 0, /* .pad2 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); #endif @@ -130,13 +130,13 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const FillOutlineDrawableUBO drawableUBO = { #endif /* .matrix=*/util::cast(matrix), - + /* .outline_color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .pad1 = */ 0, /* .pad2 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); #endif @@ -150,7 +150,8 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #endif /* .matrix = */ util::cast(matrix), /* .pixel_coord_upper = */ {static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, - /* .pixel_coord_lower = */ {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, + /* .pixel_coord_lower = */ + {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /* .tile_ratio = */ tileRatio, /* .pattern_from_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), @@ -163,13 +164,16 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #else const FillPatternTilePropsUBO tilePropsUBO = { #endif - /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, - /* .pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, - /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, - /* .pad1 = */ 0, - /* .pad2 = */ 0 + /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) + : std::array{0}, + /* .pattern_to = */ + patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + /* .texsize = */ + {static_cast(textureSize.width), static_cast(textureSize.height)}, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); drawableUniforms.createOrUpdate(idFillTilePropsUBO, &tilePropsUBO, context, true, true); @@ -184,7 +188,8 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #endif /* .matrix = */ util::cast(matrix), /* .pixel_coord_upper = */ {static_cast(pixelX >> 16), static_cast(pixelY >> 16)}, - /* .pixel_coord_lower = */ {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, + /* .pixel_coord_lower = */ + {static_cast(pixelX & 0xFFFF), static_cast(pixelY & 0xFFFF)}, /* .tile_ratio = */ tileRatio, /* .pattern_from_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), @@ -197,13 +202,16 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #else const FillOutlinePatternTilePropsUBO tilePropsUBO = { #endif - /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, - /* .pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, - /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, - /* .pad1 = */ 0, - /* .pad2 = */ 0 + /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) + : std::array{0}, + /* .pattern_to = */ + patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + /* .texsize = */ + {static_cast(textureSize.width), static_cast(textureSize.height)}, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); drawableUniforms.createOrUpdate(idFillTilePropsUBO, &tilePropsUBO, context, true, true); @@ -222,7 +230,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .pad2 = */ 0, /* .pad3 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); #endif @@ -239,7 +247,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters drawable.setUBOIndex(i++); #endif }); - + #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(FillDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.hpp b/src/mbgl/renderer/layers/fill_layer_tweaker.hpp index 7505e49c4b0..8dda28b574b 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.hpp @@ -21,7 +21,7 @@ class FillLayerTweaker : public LayerTweaker { private: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; - + #if MLN_UBO_CONSOLIDATION gfx::UniformBufferPtr drawableUniformBuffer; gfx::UniformBufferPtr tilePropsUniformBuffer; diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index 7809a55c064..4f4c2ffc917 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -50,7 +50,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet int i = 0; std::vector drawableUBOVector(layerGroup.getDrawableCount()); #endif - + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { return; @@ -69,7 +69,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet constexpr bool inViewportPixelUnits = false; const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, nearClipped, inViewportPixelUnits, drawable); - + #if MLN_UBO_CONSOLIDATION drawableUBOVector[i] = { #else @@ -89,7 +89,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet drawableUniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context, true, false); #endif }); - + #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(HeatmapDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp index d42cf1d0785..ccafc8ed4bf 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.hpp @@ -19,7 +19,7 @@ class HeatmapLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; - + #if MLN_UBO_CONSOLIDATION gfx::UniformBufferPtr drawableUniformBuffer; #endif diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index 8c849d4532e..61254467d85 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -33,13 +33,11 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint const auto& size = parameters.staticData.backendSize; matrix::ortho(matrix, 0, size.width, size.height, 0, -1, 1); - const HeatmapTexturePropsUBO propsUBO = { - /* .matrix = */ util::cast(matrix), - /* .opacity = */ evaluated.get(), - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0 - }; + const HeatmapTexturePropsUBO propsUBO = {/* .matrix = */ util::cast(matrix), + /* .opacity = */ evaluated.get(), + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}; auto& layerUniforms = layerGroup.mutableUniformBuffers(); layerUniforms.createOrUpdate(idHeatmapTexturePropsUBO, &propsUBO, parameters.context, true, true); } diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index 8a96082b48b..abf9fab6136 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -59,7 +59,7 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam std::vector drawableUBOVector(layerGroup.getDrawableCount()); std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); #endif - + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { return; @@ -69,7 +69,7 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, false, false, drawable, true); - + #if MLN_UBO_CONSOLIDATION drawableUBOVector[i] = { #else @@ -77,7 +77,7 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam #endif /* .matrix = */ util::cast(matrix) }; - + #if MLN_UBO_CONSOLIDATION tilePropsUBOVector[i] = { #else @@ -86,7 +86,7 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam /* .latrange = */ getLatRange(tileID), /* .light = */ getLight(parameters, evaluated) }; - + #if MLN_UBO_CONSOLIDATION drawable.setUBOIndex(i++); #else @@ -95,7 +95,7 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam drawableUniforms.createOrUpdate(idHillshadeTilePropsUBO, &tilePropsUBO, parameters.context, false, true); #endif }); - + #if MLN_UBO_CONSOLIDATION auto& context = parameters.context; const size_t drawableUBOVectorSize = sizeof(HillshadeDrawableUBO) * drawableUBOVector.size(); diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.hpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.hpp index 8efdbfbef23..c027ea99c42 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.hpp @@ -19,7 +19,7 @@ class HillshadeLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer; - + #if MLN_UBO_CONSOLIDATION gfx::UniformBufferPtr drawableUniformBuffer; gfx::UniformBufferPtr tilePropsUniformBuffer; diff --git a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp index e28693fefdb..4b4d5be43b1 100644 --- a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp @@ -50,15 +50,12 @@ void HillshadePrepareLayerTweaker::execute(LayerGroupBase& layerGroup, const Pai matrix::ortho(matrix, 0, util::EXTENT, -util::EXTENT, 0, -1, 1); matrix::translate(matrix, matrix, 0, -util::EXTENT, 0); - const HillshadePrepareDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(matrix) - }; + const HillshadePrepareDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix)}; const HillshadePrepareTilePropsUBO tilePropsUBO = { /* .unpack = */ getUnpackVector(drawableData.encoding), /* .dimension = */ {static_cast(drawableData.stride), static_cast(drawableData.stride)}, /* .zoom = */ static_cast(tileID.canonical.z), - /* .maxzoom = */ static_cast(drawableData.maxzoom) - }; + /* .maxzoom = */ static_cast(drawableData.maxzoom)}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idHillshadePrepareDrawableUBO, &drawableUBO, parameters.context, true, false); diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 6dad4693880..b767f570393 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -160,7 +160,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters std::vector drawableUBOVector(layerGroup.getDrawableCount()); std::vector tilePropsUBOVector(layerGroup.getDrawableCount()); #endif - + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { const auto shader = drawable.getShader(); if (!drawable.getTileID() || !shader || !checkTweakDrawable(drawable)) { @@ -197,7 +197,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #endif /* .matrix = */ util::cast(matrix), /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), - + /* .color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .blur_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), @@ -206,11 +206,11 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .width_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .pad1 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); #endif - + } break; case LineType::Gradient: { @@ -221,7 +221,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #endif /* .matrix = */ util::cast(matrix), /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, static_cast(zoom)), - + /* .blur_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .gapwidth_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), @@ -230,7 +230,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .pad1 = */ 0, /* .pad2 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); #endif @@ -263,14 +263,21 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #else const LinePatternTilePropsUBO tilePropsUBO = { #endif - /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, - /* .pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, - /* .scale = */ {parameters.pixelRatio, 1 / tileID.pixelsToTileUnits(1, intZoom), crossfade.fromScale, crossfade.toScale}, - /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, - /* .fade = */ crossfade.t, - /* .pad1 = */ 0 + /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) + : std::array{0}, + /* .pattern_to = */ + patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + /* .scale = */ + {parameters.pixelRatio, + 1 / tileID.pixelsToTileUnits(1, intZoom), + crossfade.fromScale, + crossfade.toScale}, + /* .texsize = */ + {static_cast(textureSize.width), static_cast(textureSize.height)}, + /* .fade = */ crossfade.t, + /* .pad1 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); drawableUniforms.createOrUpdate(idLineTilePropsUBO, &tilePropsUBO, context, false, true); @@ -298,7 +305,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const LinePatternPos& posB = dashPatternTexture.getTo(); const float widthA = posA.width * crossfade.fromScale; const float widthB = posB.width * crossfade.toScale; - + #if MLN_UBO_CONSOLIDATION drawableUBOVector[i].lineSDFDrawableUBO = { #else @@ -310,7 +317,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .tex_y_a = */ posA.y, /* .tex_y_b = */ posB.y, /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - + /* .color_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), /* .blur_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), /* .opacity_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), @@ -321,19 +328,19 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .pad1 = */ 0, /* .pad2 = */ 0 }; - + #if MLN_UBO_CONSOLIDATION tilePropsUBOVector[i].lineSDFTilePropsUBO = LineSDFTilePropsUBO { #else const LineSDFTilePropsUBO tilePropsUBO = { #endif - - /* .sdfgamma = */ static_cast(dashPatternTexture.getSize().width) / (std::min(widthA, widthB) * 256.0f * parameters.pixelRatio) / 2.0f, - /* .mix = */ crossfade.t, - /* .pad1 = */ 0, - /* .pad2 = */ 0 + /* .sdfgamma = */ static_cast(dashPatternTexture.getSize().width) / + (std::min(widthA, widthB) * 256.0f * parameters.pixelRatio) / 2.0f, + /* .mix = */ crossfade.t, + /* .pad1 = */ 0, + /* .pad2 = */ 0 }; - + #if !MLN_UBO_CONSOLIDATION drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); drawableUniforms.createOrUpdate(idLineTilePropsUBO, &tilePropsUBO, context, false, true); @@ -346,12 +353,12 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters "LineLayerTweaker: unknown line type: " + std::to_string(drawable.getType())); } break; } - + #if MLN_UBO_CONSOLIDATION drawable.setUBOIndex(i++); #endif }); - + #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(LineDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.hpp b/src/mbgl/renderer/layers/line_layer_tweaker.hpp index 0e27327fb73..511f18ac7c8 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.hpp @@ -64,7 +64,7 @@ class LineLayerTweaker : public LayerTweaker { gfx::UniformBufferPtr drawableUniformBuffer; gfx::UniformBufferPtr tilePropsUniformBuffer; #endif - + #if MLN_RENDER_BACKEND_METAL gfx::UniformBufferPtr expressionUniformBuffer; Unevaluated::GPUExpressions gpuExpressions; diff --git a/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp b/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp index 1db93fd9ee3..3c60a19e35d 100644 --- a/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp @@ -27,20 +27,19 @@ void LocationIndicatorLayerTweaker::execute(LayerGroupBase& layerGroup, const Pa switch (static_cast(drawable.getType())) { case RenderLocationIndicatorLayer::LocationIndicatorComponentType::Circle: { - LocationIndicatorDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(projectionCircle), - /* .color = */ props.evaluated.get() - }; - drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); + LocationIndicatorDrawableUBO drawableUBO = {/* .matrix = */ util::cast(projectionCircle), + /* .color = */ props.evaluated.get()}; + drawableUniforms.createOrUpdate( + idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); break; } case RenderLocationIndicatorLayer::LocationIndicatorComponentType::CircleOutline: { LocationIndicatorDrawableUBO drawableUBO = { /* .matrix = */ util::cast(projectionCircle), - /* .color = */ props.evaluated.get() - }; - drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); + /* .color = */ props.evaluated.get()}; + drawableUniforms.createOrUpdate( + idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); break; } @@ -49,14 +48,13 @@ void LocationIndicatorLayerTweaker::execute(LayerGroupBase& layerGroup, const Pa case RenderLocationIndicatorLayer::LocationIndicatorComponentType::Puck: [[fallthrough]]; case RenderLocationIndicatorLayer::LocationIndicatorComponentType::PuckHat: { - const LocationIndicatorDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(projectionPuck), - /* .color = */ Color::black() - }; - drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); + const LocationIndicatorDrawableUBO drawableUBO = {/* .matrix = */ util::cast(projectionPuck), + /* .color = */ Color::black()}; + drawableUniforms.createOrUpdate( + idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); break; } - + default: assert(false); break; diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index 9044a71c951..c8e9d55d9cb 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -69,7 +69,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, int i = 0; std::vector drawableUBOVector(layerGroup.getDrawableCount()); #endif - + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!checkTweakDrawable(drawable)) { return; @@ -114,7 +114,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, drawableUniforms.createOrUpdate(idRasterDrawableUBO, &drawableUBO, parameters.context, true, false); #endif }); - + #if MLN_UBO_CONSOLIDATION auto& context = parameters.context; const size_t drawableUBOVectorSize = sizeof(RasterDrawableUBO) * drawableUBOVector.size(); diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.hpp b/src/mbgl/renderer/layers/raster_layer_tweaker.hpp index 2e9107351d5..12c54976706 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.hpp @@ -24,7 +24,7 @@ class RasterLayerTweaker : public LayerTweaker { protected: gfx::UniformBufferPtr evaluatedPropsUniformBuffer = nullptr; - + #if MLN_UBO_CONSOLIDATION gfx::UniformBufferPtr drawableUniformBuffer; #endif diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index fa6ca2ede9a..81cc86f852f 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -69,21 +69,19 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete const auto zoom = static_cast(state.getZoom()); if (!evaluatedPropsUniformBuffer || propertiesUpdated) { - const SymbolEvaluatedPropsUBO propsUBO = { - /* .text_fill_color = */ constOrDefault(evaluated), - /* .text_halo_color = */ constOrDefault(evaluated), - /* .text_opacity = */ constOrDefault(evaluated), - /* .text_halo_width = */ constOrDefault(evaluated), - /* .text_halo_blur = */ constOrDefault(evaluated), - /* .pad */ 0, - - /* .icon_fill_color = */ constOrDefault(evaluated), - /* .icon_halo_color = */ constOrDefault(evaluated), - /* .icon_opacity = */ constOrDefault(evaluated), - /* .icon_halo_width = */ constOrDefault(evaluated), - /* .icon_halo_blur = */constOrDefault(evaluated), - /* .pad */ 0 - }; + const SymbolEvaluatedPropsUBO propsUBO = {/* .text_fill_color = */ constOrDefault(evaluated), + /* .text_halo_color = */ constOrDefault(evaluated), + /* .text_opacity = */ constOrDefault(evaluated), + /* .text_halo_width = */ constOrDefault(evaluated), + /* .text_halo_blur = */ constOrDefault(evaluated), + /* .pad */ 0, + + /* .icon_fill_color = */ constOrDefault(evaluated), + /* .icon_halo_color = */ constOrDefault(evaluated), + /* .icon_opacity = */ constOrDefault(evaluated), + /* .icon_halo_width = */ constOrDefault(evaluated), + /* .icon_halo_blur = */ constOrDefault(evaluated), + /* .pad */ 0}; context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } @@ -153,7 +151,7 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete const auto& sizeBinder = isText ? bucket->textSizeBinder : bucket->iconSizeBinder; const auto size = sizeBinder->evaluateForZoom(currentZoom); - + #if MLN_UBO_CONSOLIDATION drawableUBOVector[i] = { #else @@ -171,10 +169,10 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .pitch_with_map = */ (symbolData.pitchAlignment == style::AlignmentType::Map), /* .is_size_zoom_constant = */ size.isZoomConstant, /* .is_size_feature_constant = */ size.isFeatureConstant, - + /* .size_t = */ size.sizeT, /* .size = */ size.size, - + /* .fill_color_t = */ getInterpFactor(paintProperties, isText, zoom), /* .halo_color_t = */ getInterpFactor(paintProperties, isText, zoom), /* .opacity_t = */ getInterpFactor(paintProperties, isText, zoom), diff --git a/src/mbgl/renderer/paint_parameters.cpp b/src/mbgl/renderer/paint_parameters.cpp index fb94dc9b767..460e5d2278b 100644 --- a/src/mbgl/renderer/paint_parameters.cpp +++ b/src/mbgl/renderer/paint_parameters.cpp @@ -139,13 +139,11 @@ void PaintParameters::clearStencil() { #endif const std::vector tileUBO = { - shaders::ClipUBO { - /* .matrix = */ util::cast(matrixForTile({0, 0, 0})), - /* .stencil_ref = */ 0, - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0 - }}; + shaders::ClipUBO{/* .matrix = */ util::cast(matrixForTile({0, 0, 0})), + /* .stencil_ref = */ 0, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}}; mtlContext.renderTileClippingMasks(*renderPass, staticData, tileUBO); context.renderingStats().stencilClears++; #elif MLN_RENDER_BACKEND_VULKAN @@ -193,13 +191,11 @@ void PaintParameters::renderTileClippingMasks(const RenderTiles& renderTiles) { tileUBOs.reserve(count); } - tileUBOs.emplace_back(shaders::ClipUBO { - /* .matrix = */ util::cast(matrixForTile(tileID)), - /* .stencil_ref = */ static_cast(stencilID), - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0 - }); + tileUBOs.emplace_back(shaders::ClipUBO{/* .matrix = */ util::cast(matrixForTile(tileID)), + /* .stencil_ref = */ static_cast(stencilID), + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}); } if (!tileUBOs.empty()) { diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index fa7bbe62551..b32f19dc452 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -252,17 +252,15 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr }; #if MLN_ENABLE_POLYLINE_DRAWABLES - const shaders::LineEvaluatedPropsUBO linePropertiesUBO = { - /* .color = */ Color::red(), - /* .blur = */ 0.f, - /* .opacity = */ 1.f, - /* .gapwidth = */ 0.f, - /* .offset = */ 0.f, - /* .width = */ 4.f, - /* .floorwidth = */ 0, - /* .expressionMask = */ LineExpressionMask::None, - /* .pad1 = */ 0 - }; + const shaders::LineEvaluatedPropsUBO linePropertiesUBO = {/* .color = */ Color::red(), + /* .blur = */ 0.f, + /* .opacity = */ 1.f, + /* .gapwidth = */ 0.f, + /* .offset = */ 0.f, + /* .width = */ 4.f, + /* .floorwidth = */ 0, + /* .expressionMask = */ LineExpressionMask::None, + /* .pad1 = */ 0}; // function to add polylines drawable const auto addPolylineDrawable = [&](TileLayerGroup* tileLayerGroup, const RenderTile& tile) { @@ -290,20 +288,20 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const shaders::LineDrawableUBO drawableUBO = { /* .matrix = */ util::cast(matrix), /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - + /* .color_t = */ 0.f, /* .blur_t = */ 0.f, /* .opacity_t = */ 0.f, /* .gapwidth_t = */ 0.f, /* .offset_t = */ 0.f, /* .width_t = */ 0.f, - /* .pad1 = */ 0 - }; + /* .pad1 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context, true, false); #if !MLN_RENDER_BACKEND_VULKAN - drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); + drawableUniforms.createOrUpdate( + idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); @@ -377,14 +375,12 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto& debugBucket = tile.debugBucket; if (!debugBucket) continue; - const DebugUBO outlineUBO = { - /* .matrix = */ util::cast(tile.matrix), - /* .color = */ Color::white(), - /* .overlay_scale = */ 1.0f, - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0 - }; + const DebugUBO outlineUBO = {/* .matrix = */ util::cast(tile.matrix), + /* .color = */ Color::white(), + /* .overlay_scale = */ 1.0f, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}; if (0 == updateDrawables(outlineLayerGroup, tileID, outlineUBO)) { addDrawable(outlineLayerGroup, tileID, @@ -395,14 +391,12 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr debugBucket->segments); } - const DebugUBO textUBO = { - /* .matrix = */ util::cast(tile.matrix), - /* .color = */ Color::black(), - /* .overlay_scale = */ 1.0f, - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0 - }; + const DebugUBO textUBO = {/* .matrix = */ util::cast(tile.matrix), + /* .color = */ Color::black(), + /* .overlay_scale = */ 1.0f, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}; if (0 == updateDrawables(textLayerGroup, tileID, textUBO) && tile.getNeedsRendering()) { addDrawable(textLayerGroup, tileID, @@ -439,14 +433,12 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto& debugBucket = tile.debugBucket; if (!debugBucket) continue; - const DebugUBO debugUBO = { - /* .matrix = */ util::cast(tile.matrix), - /* .color = */ Color::red(), - /* .overlay_scale = */ 1.0f, - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0 - }; + const DebugUBO debugUBO = {/* .matrix = */ util::cast(tile.matrix), + /* .color = */ Color::red(), + /* .overlay_scale = */ 1.0f, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}; if (0 == updateDrawables(tileLayerGroup, tileID, debugUBO) && tile.getNeedsRendering()) { #if MLN_ENABLE_POLYLINE_DRAWABLES addPolylineDrawable(tileLayerGroup, tile); diff --git a/src/mbgl/shaders/mtl/background.cpp b/src/mbgl/shaders/mtl/background.cpp index 16a6b5c0f97..04a284c0d13 100644 --- a/src/mbgl/shaders/mtl/background.cpp +++ b/src/mbgl/shaders/mtl/background.cpp @@ -23,17 +23,15 @@ const std::array BackgroundShaderSource::textures = {}; using BackgroundPatternShaderSource = ShaderSource; -const std::arrayBackgroundPatternShaderSource::uniforms = { - UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{true, true, sizeof(BackgroundPatternPropsUBO), idBackgroundPropsUBO}, +const std::array BackgroundPatternShaderSource::uniforms = { + UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, + UniformBlockInfo{true, true, sizeof(BackgroundPatternPropsUBO), idBackgroundPropsUBO}, }; const std::array BackgroundPatternShaderSource::attributes = { - AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, -}; -const std::array BackgroundPatternShaderSource::textures = { - TextureInfo{0, idBackgroundImageTexture} + AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; +const std::array BackgroundPatternShaderSource::textures = {TextureInfo{0, idBackgroundImageTexture}}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/mtl/collision.cpp b/src/mbgl/shaders/mtl/collision.cpp index 61c3d8dfb3c..2a7a18d200b 100644 --- a/src/mbgl/shaders/mtl/collision.cpp +++ b/src/mbgl/shaders/mtl/collision.cpp @@ -28,14 +28,14 @@ const std::array CollisionBoxShaderSource::textures = {}; using CollisionCircleShaderSource = ShaderSource; const std::array CollisionCircleShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, }; const std::array CollisionCircleShaderSource::attributes = { - AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, - AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, - AttributeInfo{collisionUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, - AttributeInfo{collisionUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, + AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, + AttributeInfo{collisionUBOCount + 2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, + AttributeInfo{collisionUBOCount + 3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, }; const std::array CollisionCircleShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp index d98f363e4eb..314bd5c7374 100644 --- a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp @@ -7,7 +7,7 @@ namespace shaders { using CustomSymbolIconShaderSource = ShaderSource; const std::array CustomSymbolIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, + UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, }; const std::array CustomSymbolIconShaderSource::attributes = { AttributeInfo{customSymbolUBOCount + 0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/fill.cpp b/src/mbgl/shaders/mtl/fill.cpp index 2f18476da20..dc6dd267609 100644 --- a/src/mbgl/shaders/mtl/fill.cpp +++ b/src/mbgl/shaders/mtl/fill.cpp @@ -64,34 +64,35 @@ const std::array FillPatternShaderSource::textures = { using FillOutlinePatternShaderSource = ShaderSource; const std::array FillOutlinePatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, + UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; const std::array FillOutlinePatternShaderSource::attributes = { - AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, - AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, - AttributeInfo{fillUBOCount + 3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, + AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, + AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, + AttributeInfo{fillUBOCount + 2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, + AttributeInfo{fillUBOCount + 3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; const std::array FillOutlinePatternShaderSource::textures = { - TextureInfo{0, idFillImageTexture}, + TextureInfo{0, idFillImageTexture}, }; // // Fill outline triangulated -using FillOutlineTriangulatedShaderSource = ShaderSource; +using FillOutlineTriangulatedShaderSource = + ShaderSource; const std::array FillOutlineTriangulatedShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; const std::array FillOutlineTriangulatedShaderSource::attributes = { - AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, + AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, + AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, }; const std::array FillOutlineTriangulatedShaderSource::textures = {}; diff --git a/src/mbgl/shaders/mtl/fill_extrusion.cpp b/src/mbgl/shaders/mtl/fill_extrusion.cpp index 7eb5cea0bb0..133c813d1e0 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion.cpp @@ -10,8 +10,8 @@ namespace shaders { using FillExtrusionShaderSource = ShaderSource; const std::array FillExtrusionShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, }; const std::array FillExtrusionShaderSource::attributes = { AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, @@ -28,21 +28,22 @@ const std::array FillExtrusionShaderSource::textures = {}; using FillExtrusionPatternShaderSource = ShaderSource; const std::array FillExtrusionPatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, }; const std::array FillExtrusionPatternShaderSource::attributes = { AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 2, gfx::AttributeDataType::Float, idFillExtrusionBaseVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 3, gfx::AttributeDataType::Float, idFillExtrusionHeightVertexAttribute}, - AttributeInfo{fillExtrusionUBOCount + 4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, + AttributeInfo{ + fillExtrusionUBOCount + 4, gfx::AttributeDataType::UShort4, idFillExtrusionPatternFromVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, }; const std::array FillExtrusionPatternShaderSource::textures = { - TextureInfo{0, idFillExtrusionImageTexture}, + TextureInfo{0, idFillExtrusionImageTexture}, }; } // namespace shaders diff --git a/src/mbgl/shaders/mtl/heatmap_texture.cpp b/src/mbgl/shaders/mtl/heatmap_texture.cpp index 155dfaaa5f9..c0c16308910 100644 --- a/src/mbgl/shaders/mtl/heatmap_texture.cpp +++ b/src/mbgl/shaders/mtl/heatmap_texture.cpp @@ -7,11 +7,11 @@ namespace shaders { using HeatmapTextureShaderSource = ShaderSource; const std::array HeatmapTextureShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, }; const std::array HeatmapTextureShaderSource::attributes = { - AttributeInfo{heatmapTextureUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, + AttributeInfo{heatmapTextureUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, }; const std::array HeatmapTextureShaderSource::textures = { TextureInfo{0, idHeatmapImageTexture}, diff --git a/src/mbgl/shaders/mtl/hillshade_prepare.cpp b/src/mbgl/shaders/mtl/hillshade_prepare.cpp index 60df912c35c..49b9f7a6507 100644 --- a/src/mbgl/shaders/mtl/hillshade_prepare.cpp +++ b/src/mbgl/shaders/mtl/hillshade_prepare.cpp @@ -7,8 +7,8 @@ namespace shaders { using HillshadePrepareShaderSource = ShaderSource; const std::array HillshadePrepareShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, - UniformBlockInfo{true, true, sizeof(HillshadePrepareTilePropsUBO), idHillshadePrepareTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, + UniformBlockInfo{true, true, sizeof(HillshadePrepareTilePropsUBO), idHillshadePrepareTilePropsUBO}, }; const std::array HillshadePrepareShaderSource::attributes = { AttributeInfo{hillshadePrepareUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/symbol.cpp b/src/mbgl/shaders/mtl/symbol.cpp index a8435cf3406..8c5a1608157 100644 --- a/src/mbgl/shaders/mtl/symbol.cpp +++ b/src/mbgl/shaders/mtl/symbol.cpp @@ -36,25 +36,25 @@ const std::array SymbolIconShaderSource::textures = { using SymbolSDFIconShaderSource = ShaderSource; const std::array SymbolSDFIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, }; const std::array SymbolSDFIconShaderSource::attributes = { - // always attributes - AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + // always attributes + AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, - // sometimes uniforms - AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{symbolUBOCount + 9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, + // sometimes uniforms + AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{symbolUBOCount + 9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, }; const std::array SymbolSDFIconShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, @@ -66,24 +66,24 @@ const std::array SymbolSDFIconShaderSource::textures = { using SymbolTextAndIconShaderSource = ShaderSource; const std::array SymbolTextAndIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, }; const std::array SymbolTextAndIconShaderSource::attributes = { - // always attributes - AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + // always attributes + AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{symbolUBOCount + 1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{symbolUBOCount + 2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{symbolUBOCount + 3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, - // sometimes uniforms - AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, + // sometimes uniforms + AttributeInfo{symbolUBOCount + 4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, + AttributeInfo{symbolUBOCount + 6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{symbolUBOCount + 7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{symbolUBOCount + 8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, }; const std::array SymbolTextAndIconShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, diff --git a/src/mbgl/shaders/vulkan/background.cpp b/src/mbgl/shaders/vulkan/background.cpp index 1096ddcef38..f8aaa0e0b70 100644 --- a/src/mbgl/shaders/vulkan/background.cpp +++ b/src/mbgl/shaders/vulkan/background.cpp @@ -24,17 +24,15 @@ const std::array BackgroundShaderSource::textures = {}; using BackgroundPatternShaderSource = ShaderSource; -const std::arrayBackgroundPatternShaderSource::uniforms = { - UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{true, true, sizeof(BackgroundPatternPropsUBO), idBackgroundPropsUBO}, +const std::array BackgroundPatternShaderSource::uniforms = { + UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, + UniformBlockInfo{true, true, sizeof(BackgroundPatternPropsUBO), idBackgroundPropsUBO}, }; const std::array BackgroundPatternShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, -}; -const std::array BackgroundPatternShaderSource::textures = { - TextureInfo{0, idBackgroundImageTexture} + AttributeInfo{0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; +const std::array BackgroundPatternShaderSource::textures = {TextureInfo{0, idBackgroundImageTexture}}; } // namespace shaders } // namespace mbgl diff --git a/src/mbgl/shaders/vulkan/collision.cpp b/src/mbgl/shaders/vulkan/collision.cpp index 0e00e65012d..6c11c4de301 100644 --- a/src/mbgl/shaders/vulkan/collision.cpp +++ b/src/mbgl/shaders/vulkan/collision.cpp @@ -29,14 +29,14 @@ const std::array CollisionBoxShaderSource::textures = {}; using CollisionCircleShaderSource = ShaderSource; const std::array CollisionCircleShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, }; const std::array CollisionCircleShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Short2, idCollisionExtrudeVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::UShort2, idCollisionPlacedVertexAttribute}, }; const std::array CollisionCircleShaderSource::textures = {}; diff --git a/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp b/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp index 3fb20a04354..4b6cf37d561 100644 --- a/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp +++ b/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp @@ -8,7 +8,7 @@ namespace shaders { using CustomSymbolIconShaderSource = ShaderSource; const std::array CustomSymbolIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, + UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, }; const std::array CustomSymbolIconShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/fill.cpp b/src/mbgl/shaders/vulkan/fill.cpp index 2f46c2463dc..1df2fd742c0 100644 --- a/src/mbgl/shaders/vulkan/fill.cpp +++ b/src/mbgl/shaders/vulkan/fill.cpp @@ -65,34 +65,35 @@ const std::array FillPatternShaderSource::textures = { using FillOutlinePatternShaderSource = ShaderSource; const std::array FillOutlinePatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, + UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; const std::array FillOutlinePatternShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::UShort4, idFillPatternToVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float2, idFillOpacityVertexAttribute}, }; const std::array FillOutlinePatternShaderSource::textures = { - TextureInfo{0, idFillImageTexture}, + TextureInfo{0, idFillImageTexture}, }; // // Fill outline triangulated -using FillOutlineTriangulatedShaderSource = ShaderSource; +using FillOutlineTriangulatedShaderSource = + ShaderSource; const std::array FillOutlineTriangulatedShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, + UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, }; const std::array FillOutlineTriangulatedShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, }; const std::array FillOutlineTriangulatedShaderSource::textures = {}; diff --git a/src/mbgl/shaders/vulkan/fill_extrusion.cpp b/src/mbgl/shaders/vulkan/fill_extrusion.cpp index a10e747daf0..d73eeddd5bd 100644 --- a/src/mbgl/shaders/vulkan/fill_extrusion.cpp +++ b/src/mbgl/shaders/vulkan/fill_extrusion.cpp @@ -11,8 +11,8 @@ namespace shaders { using FillExtrusionShaderSource = ShaderSource; const std::array FillExtrusionShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, }; const std::array FillExtrusionShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, @@ -29,10 +29,10 @@ const std::array FillExtrusionShaderSource::textures = {}; using FillExtrusionPatternShaderSource = ShaderSource; const std::array FillExtrusionPatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, + UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, }; const std::array FillExtrusionPatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, @@ -43,7 +43,7 @@ const std::array FillExtrusionPatternShaderSource::attributes AttributeInfo{5, gfx::AttributeDataType::UShort4, idFillExtrusionPatternToVertexAttribute}, }; const std::array FillExtrusionPatternShaderSource::textures = { - TextureInfo{0, idFillExtrusionImageTexture}, + TextureInfo{0, idFillExtrusionImageTexture}, }; } // namespace shaders diff --git a/src/mbgl/shaders/vulkan/heatmap_texture.cpp b/src/mbgl/shaders/vulkan/heatmap_texture.cpp index 6b64bb891d0..16b9bdd99aa 100644 --- a/src/mbgl/shaders/vulkan/heatmap_texture.cpp +++ b/src/mbgl/shaders/vulkan/heatmap_texture.cpp @@ -8,11 +8,11 @@ namespace shaders { using HeatmapTextureShaderSource = ShaderSource; const std::array HeatmapTextureShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, }; const std::array HeatmapTextureShaderSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, }; const std::array HeatmapTextureShaderSource::textures = { TextureInfo{0, idHeatmapImageTexture}, diff --git a/src/mbgl/shaders/vulkan/hillshade_prepare.cpp b/src/mbgl/shaders/vulkan/hillshade_prepare.cpp index 777aee07034..04cd8f9eac3 100644 --- a/src/mbgl/shaders/vulkan/hillshade_prepare.cpp +++ b/src/mbgl/shaders/vulkan/hillshade_prepare.cpp @@ -8,8 +8,8 @@ namespace shaders { using HillshadePrepareShaderSource = ShaderSource; const std::array HillshadePrepareShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, - UniformBlockInfo{true, true, sizeof(HillshadePrepareTilePropsUBO), idHillshadePrepareTilePropsUBO}, + UniformBlockInfo{true, false, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, + UniformBlockInfo{true, true, sizeof(HillshadePrepareTilePropsUBO), idHillshadePrepareTilePropsUBO}, }; const std::array HillshadePrepareShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/location_indicator.cpp b/src/mbgl/shaders/vulkan/location_indicator.cpp index 3275153ce27..c0c4c6f8462 100644 --- a/src/mbgl/shaders/vulkan/location_indicator.cpp +++ b/src/mbgl/shaders/vulkan/location_indicator.cpp @@ -21,14 +21,15 @@ const std::array LocationIndicatorShaderSource::textures = {}; // // Location indicator textured -using LocationIndicatorShaderTexturedSource = ShaderSource; +using LocationIndicatorShaderTexturedSource = + ShaderSource; const std::array LocationIndicatorShaderTexturedSource::uniforms = { - UniformBlockInfo{true, false, sizeof(LocationIndicatorDrawableUBO), idLocationIndicatorDrawableUBO}, + UniformBlockInfo{true, false, sizeof(LocationIndicatorDrawableUBO), idLocationIndicatorDrawableUBO}, }; const std::array LocationIndicatorShaderTexturedSource::attributes = { - AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::Float2, idCommonTexVertexAttribute}, + AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::Float2, idCommonTexVertexAttribute}, }; const std::array LocationIndicatorShaderTexturedSource::textures = { TextureInfo{0, idCommonTexture}, diff --git a/src/mbgl/shaders/vulkan/symbol.cpp b/src/mbgl/shaders/vulkan/symbol.cpp index 3bcab1cd451..068b4cb51ac 100644 --- a/src/mbgl/shaders/vulkan/symbol.cpp +++ b/src/mbgl/shaders/vulkan/symbol.cpp @@ -37,25 +37,25 @@ const std::array SymbolIconShaderSource::textures = { using SymbolSDFIconShaderSource = ShaderSource; const std::array SymbolSDFIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, }; const std::array SymbolSDFIconShaderSource::attributes = { - // always attributes - AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + // always attributes + AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Short4, idSymbolPixelOffsetVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{4, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, - // sometimes uniforms - AttributeInfo{5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, + // sometimes uniforms + AttributeInfo{5, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{8, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{9, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, }; const std::array SymbolSDFIconShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, @@ -67,24 +67,24 @@ const std::array SymbolSDFIconShaderSource::textures = { using SymbolTextAndIconShaderSource = ShaderSource; const std::array SymbolTextAndIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, + UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, + UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, + UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, + UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, }; const std::array SymbolTextAndIconShaderSource::attributes = { - // always attributes - AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, - AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, - AttributeInfo{2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, - AttributeInfo{3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, + // always attributes + AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, + AttributeInfo{1, gfx::AttributeDataType::UShort4, idSymbolDataVertexAttribute}, + AttributeInfo{2, gfx::AttributeDataType::Float3, idSymbolProjectedPosVertexAttribute}, + AttributeInfo{3, gfx::AttributeDataType::Float, idSymbolFadeOpacityVertexAttribute}, - // sometimes uniforms - AttributeInfo{4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, - AttributeInfo{5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, - AttributeInfo{6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, - AttributeInfo{7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, - AttributeInfo{8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, + // sometimes uniforms + AttributeInfo{4, gfx::AttributeDataType::Float4, idSymbolColorVertexAttribute}, + AttributeInfo{5, gfx::AttributeDataType::Float4, idSymbolHaloColorVertexAttribute}, + AttributeInfo{6, gfx::AttributeDataType::Float, idSymbolOpacityVertexAttribute}, + AttributeInfo{7, gfx::AttributeDataType::Float, idSymbolHaloWidthVertexAttribute}, + AttributeInfo{8, gfx::AttributeDataType::Float, idSymbolHaloBlurVertexAttribute}, }; const std::array SymbolTextAndIconShaderSource::textures = { TextureInfo{0, idSymbolImageTexture}, diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index c7b91dc697f..e9b2da70cae 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -108,18 +108,16 @@ class LineDrawableTweaker : public gfx::DrawableTweaker { const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::LineDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(matrix), - /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - - /* .color_t = */ 0.f, - /* .blur_t = */ 0.f, - /* .opacity_t = */ 0.f, - /* .gapwidth_t = */ 0.f, - /* .offset_t = */ 0.f, - /* .width_t = */ 0.f, - /* .pad1 = */ 0 - }; + const shaders::LineDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), + + /* .color_t = */ 0.f, + /* .blur_t = */ 0.f, + /* .opacity_t = */ 0.f, + /* .gapwidth_t = */ 0.f, + /* .offset_t = */ 0.f, + /* .width_t = */ 0.f, + /* .pad1 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context, true, false); drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); @@ -171,24 +169,22 @@ class WideVectorDrawableTweaker : public gfx::DrawableTweaker { /* .pMatrixDiff = */ pMatrixDiff, /* .frameSize = */ {(float)renderableSize.width, (float)renderableSize.height}, /* .pad1 = */ 0, - /* .pad2 = */ 0 - }; + /* .pad2 = */ 0}; shaders::WideVectorUniformWideVecUBO wideVec = { /* .color = */ options.color, /* .w2 = */ options.width, /* .offset = */ options.offset, - /* .edge = */ 0.0f, // TODO: MLN does not provide a value. Analyze impact. - /* .texRepeat = */ 0.0f, // N/A - /* .texOffset = */ {}, // N/A + /* .edge = */ 0.0f, // TODO: MLN does not provide a value. Analyze impact. + /* .texRepeat = */ 0.0f, // N/A + /* .texOffset = */ {}, // N/A /* .miterLimit = */ options.geometry.miterLimit, /* .join = */ static_cast(options.geometry.joinType), /* .cap = */ static_cast(options.geometry.beginCap), // TODO: MLN option for endCap to be // implemented in the shader! /* .hasExp = */ false, // N/A /* .interClipLimit = */ 0.0f, // N/A - /* .pad1 = */ 0 - }; + /* .pad1 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idWideVectorUniformsUBO, &uniform, parameters.context, true, false); @@ -220,23 +216,19 @@ class FillDrawableTweaker : public gfx::DrawableTweaker { const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::FillDrawableUBO fillDrawableUBO = { - /* .matrix = */ util::cast(matrix), - - /* .color_t = */ 0.f, - /* .opacity_t = */ 0.f, - /* .pad1 = */ 0, - /* .pad2 = */ 0 - }; + const shaders::FillDrawableUBO fillDrawableUBO = {/* .matrix = */ util::cast(matrix), - const shaders::FillEvaluatedPropsUBO fillPropertiesUBO = { - /* .color = */ color, - /* .outline_color = */ Color::white(), - /* .opacity = */ opacity, - /* .fade = */ 0.f, - /* .from_scale = */ 0.f, - /* .to_scale = */ 0.f - }; + /* .color_t = */ 0.f, + /* .opacity_t = */ 0.f, + /* .pad1 = */ 0, + /* .pad2 = */ 0}; + + const shaders::FillEvaluatedPropsUBO fillPropertiesUBO = {/* .color = */ color, + /* .outline_color = */ Color::white(), + /* .opacity = */ opacity, + /* .fade = */ 0.f, + /* .from_scale = */ 0.f, + /* .to_scale = */ 0.f}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idFillDrawableUBO, &fillDrawableUBO, parameters.context, true, false); drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context, true, true); @@ -287,8 +279,7 @@ class SymbolDrawableTweaker : public gfx::DrawableTweaker { /* .aspect_ratio = */ parameters.pixelsToGLUnits[0] / parameters.pixelsToGLUnits[1], /* .pad1 = */ 0, /* .pad2 = */ 0, - /* .pad3 = */ 0 - }; + /* .pad3 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idCustomSymbolDrawableUBO, &drawableUBO, parameters.context, true, false); diff --git a/src/mbgl/vulkan/context.cpp b/src/mbgl/vulkan/context.cpp index 2bdca00d583..0f71d20875d 100644 --- a/src/mbgl/vulkan/context.cpp +++ b/src/mbgl/vulkan/context.cpp @@ -444,9 +444,9 @@ void Context::bindGlobalUniformBuffers(gfx::RenderPass& renderPass) const noexce const shaders::GlobalPlatformParamsUBO platformUBO = { /* .rotation0 = */ {cosf(surfaceRotation), -sinf(surfaceRotation)}, - /* .rotation1 = */ {sinf(surfaceRotation), cosf(surfaceRotation)} - }; - context.globalUniformBuffers.createOrUpdate(shaders::idGlobalPlatformParamsUBO, &platformUBO, sizeof(platformUBO), context, true, true); + /* .rotation1 = */ {sinf(surfaceRotation), cosf(surfaceRotation)}}; + context.globalUniformBuffers.createOrUpdate( + shaders::idGlobalPlatformParamsUBO, &platformUBO, sizeof(platformUBO), context, true, true); } context.globalUniformBuffers.bindDescriptorSets(renderPassImpl.getEncoder()); From 1080933ab90d3ada5d437dedef9ffcff77cce98e Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Fri, 13 Dec 2024 01:20:15 +0200 Subject: [PATCH 03/13] Typo. --- src/mbgl/renderer/layers/symbol_layer_tweaker.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index 81cc86f852f..65a3d4ea014 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -74,14 +74,14 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .text_opacity = */ constOrDefault(evaluated), /* .text_halo_width = */ constOrDefault(evaluated), /* .text_halo_blur = */ constOrDefault(evaluated), - /* .pad */ 0, + /* .pad1 */ 0, /* .icon_fill_color = */ constOrDefault(evaluated), /* .icon_halo_color = */ constOrDefault(evaluated), /* .icon_opacity = */ constOrDefault(evaluated), /* .icon_halo_width = */ constOrDefault(evaluated), /* .icon_halo_blur = */ constOrDefault(evaluated), - /* .pad */ 0}; + /* .pad2 */ 0}; context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } From c2743c0472c298427475a77c1216b1c548a7e87c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:20:44 +0000 Subject: [PATCH 04/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/mbgl/renderer/layers/fill_layer_tweaker.cpp | 4 ++-- src/mbgl/renderer/layers/line_layer_tweaker.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 1f3a35bb332..5d070465e9b 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -167,7 +167,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, /* .pattern_to = */ - patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, /* .pad1 = */ 0, @@ -205,7 +205,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, /* .pattern_to = */ - patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, /* .pad1 = */ 0, diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index b767f570393..0f5ab8b08bf 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -266,7 +266,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, /* .pattern_to = */ - patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, /* .scale = */ {parameters.pixelRatio, 1 / tileID.pixelsToTileUnits(1, intZoom), From 278e2cae8ccf1a24b451b990253f51da79d1e559 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Fri, 13 Dec 2024 01:33:38 +0200 Subject: [PATCH 05/13] Code spacing. --- .../renderer/layers/circle_layer_tweaker.cpp | 2 +- .../layers/fill_extrusion_layer_tweaker.cpp | 8 +++--- .../renderer/layers/line_layer_tweaker.cpp | 14 +++++----- .../renderer/layers/raster_layer_tweaker.cpp | 26 +++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index fdb86b06f8d..d8cb610acd6 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -51,7 +51,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .stroke_opacity = */ constOrDefault(evaluated), /* .scale_with_map = */ scaleWithMap, /* .pitch_with_map = */ pitchWithMap, - /* .padding = */ 0}; + /* .pad1 = */ 0}; context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); propertiesUpdated = false; } diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index 50295570b89..0d4aba89913 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -44,7 +44,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP const FillExtrusionPropsUBO propsUBO = { /* .color = */ constOrDefault(evaluated), /* .light_color = */ FillExtrusionProgram::lightColor(parameters.evaluatedLight), - /* .pad = */ 0, + /* .pad1 = */ 0, /* .light_position = */ FillExtrusionProgram::lightPosition(parameters.evaluatedLight, state), /* .base = */ constOrDefault(evaluated), /* .height = */ constOrDefault(evaluated), @@ -54,7 +54,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP /* .fade = */ crossfade.t, /* .from_scale = */ crossfade.fromScale, /* .to_scale = */ crossfade.toScale, - /* .pad = */ 0}; + /* .pad2 = */ 0}; auto& layerUniforms = layerGroup.mutableUniformBuffers(); layerUniforms.createOrUpdate(idFillExtrusionPropsUBO, &propsUBO, context, true, true); @@ -136,8 +136,8 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP #else const FillExtrusionTilePropsUBO tilePropsUBO = { #endif - /* pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, - /* pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, + /* .pattern_from = */ patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, + /* .pattern_to = */ patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}, /* .texsize = */ {static_cast(textureSize.width), static_cast(textureSize.height)}, /* .pad1 = */ 0, /* .pad2 = */ 0 diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 0f5ab8b08bf..f76fca573df 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -318,13 +318,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /* .tex_y_b = */ posB.y, /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - /* .color_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .blur_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .opacity_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .gapwidth_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .offset_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .width_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), - /* .floorwidth_t =*/std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .color_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .blur_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .opacity_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .gapwidth_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .offset_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .width_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), + /* .floorwidth_t = */ std::get<0>(binders->get()->interpolationFactor(zoom)), /* .pad1 = */ 0, /* .pad2 = */ 0 }; diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index c8e9d55d9cb..442da2c7583 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -47,18 +47,18 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, if (!evaluatedPropsUniformBuffer || propertiesUpdated) { const RasterEvaluatedPropsUBO propsUBO = { - /*.spin_weigths = */ spinWeights(evaluated.get()), - /*.tl_parent = */ {{0.0f, 0.0f}}, - /*.scale_parent = */ 1.0f, - /*.buffer_scale = */ 1.0f, - /*.fade_t = */ 1.0f, - /*.opacity = */ evaluated.get(), - /*.brightness_low = */ evaluated.get(), - /*.brightness_high = */ evaluated.get(), - /*.saturation_factor = */ saturationFactor(evaluated.get()), - /*.contrast_factor = */ contrastFactor(evaluated.get()), - 0, - 0}; + /* .spin_weigths = */ spinWeights(evaluated.get()), + /* .tl_parent = */ {{0.0f, 0.0f}}, + /* .scale_parent = */ 1.0f, + /* .buffer_scale = */ 1.0f, + /* .fade_t = */ 1.0f, + /* .opacity = */ evaluated.get(), + /* .brightness_low = */ evaluated.get(), + /* .brightness_high = */ evaluated.get(), + /* .saturation_factor = */ saturationFactor(evaluated.get()), + /* .contrast_factor = */ contrastFactor(evaluated.get()), + /* .pad1 = */ 0, + /* .pad2 = */ 0}; parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &propsUBO); propertiesUpdated = false; } @@ -105,7 +105,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, #else const RasterDrawableUBO drawableUBO = { #endif - /*.matrix = */ util::cast(matrix) + /* .matrix = */ util::cast(matrix) }; #if MLN_UBO_CONSOLIDATION drawable.setUBOIndex(i++); From 42e7a76ed75e8ddb2564658de3d57e793f8df992 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Fri, 13 Dec 2024 01:51:22 +0200 Subject: [PATCH 06/13] Added missing files. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2b51e4dee6..8555c3e6ca2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1035,6 +1035,7 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_circle.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_collision_box.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_collision_circle.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_custom_symbol_icon.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_debug.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_fill.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_fill_outline.hpp @@ -1051,10 +1052,13 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_line_gradient.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_line_pattern.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_line_sdf.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_location_indicator.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_raster.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_symbol_icon.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_symbol_sdf.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_symbol_text_and_icon.hpp + ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/drawable_wide_vector.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/background_pattern.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/circle.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/shaders/gl/clipping_mask.hpp From 906f7082fd784b36b7078748ee4a7e80632bc7c9 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Fri, 13 Dec 2024 02:17:59 +0200 Subject: [PATCH 07/13] Fix CI. --- bazel/core.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bazel/core.bzl b/bazel/core.bzl index 0305c43dfd5..63c1ee32c82 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -84,6 +84,8 @@ MLN_GENERATED_OPENGL_SHADER_HEADERS = [ "include/mbgl/shaders/gl/drawable_line_pattern.hpp", "include/mbgl/shaders/gl/drawable_line_sdf.hpp", "include/mbgl/shaders/gl/drawable_line.hpp", + "include/mbgl/shaders/gl/drawable_location_indicator.hpp", + "include/mbgl/shaders/gl/drawable_location_indicator_textured.hpp", "include/mbgl/shaders/gl/drawable_raster.hpp", "include/mbgl/shaders/gl/drawable_symbol_icon.hpp", "include/mbgl/shaders/gl/drawable_symbol_sdf.hpp", From e3c2a15e3433ee2500924ce2d74c0b64dff920a2 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Sat, 14 Dec 2024 00:27:48 +0200 Subject: [PATCH 08/13] Removed uniform blocks. --- CMakeLists.txt | 6 - bazel/core.bzl | 6 - include/mbgl/gfx/uniform_block.hpp | 114 --------- include/mbgl/gfx/uniform_buffer.hpp | 21 +- include/mbgl/gl/uniform_block_gl.hpp | 49 ---- include/mbgl/mtl/uniform_block.hpp | 59 ----- include/mbgl/shaders/gl/shader_program_gl.hpp | 8 - include/mbgl/shaders/layer_ubo.hpp | 8 +- include/mbgl/shaders/mtl/background.hpp | 16 +- include/mbgl/shaders/mtl/circle.hpp | 13 +- include/mbgl/shaders/mtl/clipping_mask.hpp | 11 +- include/mbgl/shaders/mtl/collision.hpp | 14 +- include/mbgl/shaders/mtl/common.hpp | 6 + .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 11 +- include/mbgl/shaders/mtl/debug.hpp | 13 +- include/mbgl/shaders/mtl/fill.hpp | 23 +- include/mbgl/shaders/mtl/fill_extrusion.hpp | 18 +- include/mbgl/shaders/mtl/heatmap.hpp | 13 +- include/mbgl/shaders/mtl/heatmap_texture.hpp | 11 +- include/mbgl/shaders/mtl/hillshade.hpp | 15 +- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 15 +- include/mbgl/shaders/mtl/line.hpp | 22 +- include/mbgl/shaders/mtl/raster.hpp | 13 +- include/mbgl/shaders/mtl/shader_group.hpp | 3 - include/mbgl/shaders/mtl/shader_program.hpp | 6 - include/mbgl/shaders/mtl/symbol.hpp | 21 +- include/mbgl/shaders/mtl/widevector.hpp | 5 +- include/mbgl/shaders/shader_defines.hpp | 68 +++--- include/mbgl/shaders/shader_program_base.hpp | 7 - include/mbgl/shaders/vulkan/background.hpp | 31 ++- include/mbgl/shaders/vulkan/circle.hpp | 21 +- include/mbgl/shaders/vulkan/clipping_mask.hpp | 1 - include/mbgl/shaders/vulkan/collision.hpp | 28 ++- include/mbgl/shaders/vulkan/common.hpp | 10 + .../shaders/vulkan/custom_symbol_icon.hpp | 16 +- include/mbgl/shaders/vulkan/debug.hpp | 16 +- include/mbgl/shaders/vulkan/fill.hpp | 70 +++--- .../mbgl/shaders/vulkan/fill_extrusion.hpp | 35 +-- include/mbgl/shaders/vulkan/heatmap.hpp | 19 +- .../mbgl/shaders/vulkan/heatmap_texture.hpp | 16 +- include/mbgl/shaders/vulkan/hillshade.hpp | 20 +- .../mbgl/shaders/vulkan/hillshade_prepare.hpp | 19 +- include/mbgl/shaders/vulkan/line.hpp | 59 +++-- .../shaders/vulkan/location_indicator.hpp | 19 +- include/mbgl/shaders/vulkan/raster.hpp | 19 +- include/mbgl/shaders/vulkan/shader_group.hpp | 3 - .../mbgl/shaders/vulkan/shader_program.hpp | 5 - include/mbgl/shaders/vulkan/symbol.hpp | 44 ++-- include/mbgl/shaders/vulkan/widevector.hpp | 34 +-- include/mbgl/vulkan/context.hpp | 1 + include/mbgl/vulkan/uniform_block.hpp | 59 ----- include/mbgl/vulkan/uniform_buffer.hpp | 7 +- src/mbgl/gfx/uniform_block.cpp | 39 --- src/mbgl/gfx/uniform_buffer.cpp | 19 +- src/mbgl/gl/uniform_block_gl.cpp | 31 --- src/mbgl/mtl/context.cpp | 2 +- src/mbgl/mtl/drawable.cpp | 1 - src/mbgl/mtl/uniform_block.cpp | 17 -- src/mbgl/mtl/uniform_buffer.cpp | 5 +- .../layers/background_layer_tweaker.cpp | 10 +- .../renderer/layers/circle_layer_tweaker.cpp | 6 +- .../layers/collision_layer_tweaker.cpp | 4 +- .../layers/fill_extrusion_layer_tweaker.cpp | 10 +- .../renderer/layers/fill_layer_tweaker.cpp | 20 +- .../renderer/layers/heatmap_layer_tweaker.cpp | 6 +- .../layers/heatmap_texture_layer_tweaker.cpp | 2 +- .../layers/hillshade_layer_tweaker.cpp | 10 +- .../hillshade_prepare_layer_tweaker.cpp | 4 +- .../renderer/layers/line_layer_tweaker.cpp | 20 +- .../location_indicator_layer_tweaker.cpp | 9 +- .../renderer/layers/raster_layer_tweaker.cpp | 6 +- .../renderer/layers/symbol_layer_tweaker.cpp | 10 +- src/mbgl/renderer/renderer_impl.cpp | 2 +- .../renderer/sources/render_tile_source.cpp | 15 +- src/mbgl/shaders/gl/shader_info.cpp | 230 ++++++++++-------- src/mbgl/shaders/gl/shader_program_gl.cpp | 8 +- src/mbgl/shaders/mtl/background.cpp | 9 - src/mbgl/shaders/mtl/circle.cpp | 5 - src/mbgl/shaders/mtl/clipping_mask.cpp | 3 - src/mbgl/shaders/mtl/collision.cpp | 8 - src/mbgl/shaders/mtl/custom_symbol_icon.cpp | 3 - src/mbgl/shaders/mtl/debug.cpp | 3 - src/mbgl/shaders/mtl/fill.cpp | 26 -- src/mbgl/shaders/mtl/fill_extrusion.cpp | 10 - src/mbgl/shaders/mtl/heatmap.cpp | 4 - src/mbgl/shaders/mtl/heatmap_texture.cpp | 4 - src/mbgl/shaders/mtl/hillshade.cpp | 5 - src/mbgl/shaders/mtl/hillshade_prepare.cpp | 4 - src/mbgl/shaders/mtl/line.cpp | 25 -- src/mbgl/shaders/mtl/raster.cpp | 4 - src/mbgl/shaders/mtl/shader_program.cpp | 18 -- src/mbgl/shaders/mtl/symbol.cpp | 18 -- src/mbgl/shaders/mtl/widevector.cpp | 4 - src/mbgl/shaders/vulkan/background.cpp | 9 - src/mbgl/shaders/vulkan/circle.cpp | 5 - src/mbgl/shaders/vulkan/clipping_mask.cpp | 1 - src/mbgl/shaders/vulkan/collision.cpp | 8 - .../shaders/vulkan/custom_symbol_icon.cpp | 3 - src/mbgl/shaders/vulkan/debug.cpp | 3 - src/mbgl/shaders/vulkan/fill.cpp | 26 -- src/mbgl/shaders/vulkan/fill_extrusion.cpp | 10 - src/mbgl/shaders/vulkan/heatmap.cpp | 4 - src/mbgl/shaders/vulkan/heatmap_texture.cpp | 4 - src/mbgl/shaders/vulkan/hillshade.cpp | 5 - src/mbgl/shaders/vulkan/hillshade_prepare.cpp | 4 - src/mbgl/shaders/vulkan/line.cpp | 22 -- .../shaders/vulkan/location_indicator.cpp | 6 - src/mbgl/shaders/vulkan/raster.cpp | 4 - src/mbgl/shaders/vulkan/shader_program.cpp | 16 -- src/mbgl/shaders/vulkan/symbol.cpp | 18 -- src/mbgl/shaders/vulkan/widevector.cpp | 4 - .../style/layers/custom_drawable_layer.cpp | 14 +- src/mbgl/vulkan/context.cpp | 21 +- src/mbgl/vulkan/uniform_buffer.cpp | 12 +- 114 files changed, 671 insertions(+), 1314 deletions(-) delete mode 100644 include/mbgl/gfx/uniform_block.hpp delete mode 100644 include/mbgl/gl/uniform_block_gl.hpp delete mode 100644 include/mbgl/mtl/uniform_block.hpp delete mode 100644 include/mbgl/vulkan/uniform_block.hpp delete mode 100644 src/mbgl/gfx/uniform_block.cpp delete mode 100644 src/mbgl/gl/uniform_block_gl.cpp delete mode 100644 src/mbgl/mtl/uniform_block.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8555c3e6ca2..36258a3b4b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,6 @@ if(MLN_DRAWABLE_RENDERER) ${PROJECT_SOURCE_DIR}/include/mbgl/gfx/drawable_atlases_tweaker.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gfx/drawable_custom_layer_host_tweaker.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gfx/gpu_expression.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/gfx/uniform_block.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gfx/uniform_buffer.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gfx/vertex_attribute.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gfx/texture2d.hpp @@ -177,7 +176,6 @@ if(MLN_DRAWABLE_RENDERER) ${PROJECT_SOURCE_DIR}/src/mbgl/gfx/line_drawable_data.hpp ${PROJECT_SOURCE_DIR}/src/mbgl/gfx/symbol_drawable_data.hpp ${PROJECT_SOURCE_DIR}/src/mbgl/gfx/collision_drawable_data.hpp - ${PROJECT_SOURCE_DIR}/src/mbgl/gfx/uniform_block.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/gfx/uniform_buffer.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/gfx/vertex_attribute.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/renderer/render_target.cpp @@ -1165,7 +1163,6 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/drawable_gl_builder.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/layer_group_gl.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/gl/uniform_block_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/uniform_buffer_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/vertex_attribute_gl.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/gl/texture2d.hpp @@ -1179,7 +1176,6 @@ if(MLN_WITH_OPENGL) ${PROJECT_SOURCE_DIR}/src/mbgl/gl/drawable_gl_impl.hpp ${PROJECT_SOURCE_DIR}/src/mbgl/gl/layer_group_gl.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/gl/texture2d.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/gl/uniform_block_gl.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/gl/uniform_buffer_gl.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/gl/vertex_attribute_gl.cpp ) @@ -1210,7 +1206,6 @@ if(MLN_WITH_METAL) ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/renderable_resource.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/texture2d.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/tile_layer_group.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/uniform_block.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/uniform_buffer.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/upload_pass.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/mtl/vertex_attribute.hpp @@ -1250,7 +1245,6 @@ if(MLN_WITH_METAL) ${PROJECT_SOURCE_DIR}/src/mbgl/mtl/texture2d.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/mtl/render_pass.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/mtl/tile_layer_group.cpp - ${PROJECT_SOURCE_DIR}/src/mbgl/mtl/uniform_block.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/mtl/uniform_buffer.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/mtl/upload_pass.cpp ${PROJECT_SOURCE_DIR}/src/mbgl/mtl/vertex_attribute.cpp diff --git a/bazel/core.bzl b/bazel/core.bzl index 63c1ee32c82..7f4ca59f53d 100644 --- a/bazel/core.bzl +++ b/bazel/core.bzl @@ -942,7 +942,6 @@ MLN_DRAWABLES_SOURCE = [ "src/mbgl/gfx/line_drawable_data.hpp", "src/mbgl/gfx/symbol_drawable_data.hpp", "src/mbgl/gfx/collision_drawable_data.hpp", - "src/mbgl/gfx/uniform_block.cpp", "src/mbgl/gfx/uniform_buffer.cpp", "src/mbgl/gfx/vertex_attribute.cpp", "src/mbgl/renderer/change_request.cpp", @@ -994,7 +993,6 @@ MLN_DRAWABLES_HEADERS = [ "include/mbgl/gfx/drawable_atlases_tweaker.hpp", "include/mbgl/gfx/drawable_custom_layer_host_tweaker.hpp", "include/mbgl/gfx/gpu_expression.hpp", - "include/mbgl/gfx/uniform_block.hpp", "include/mbgl/gfx/uniform_buffer.hpp", "include/mbgl/gfx/vertex_attribute.hpp", "include/mbgl/gfx/texture2d.hpp", @@ -1033,7 +1031,6 @@ MLN_DRAWABLES_GL_SOURCE = [ "src/mbgl/gl/drawable_gl_impl.hpp", "src/mbgl/gl/layer_group_gl.cpp", "src/mbgl/gl/texture2d.cpp", - "src/mbgl/gl/uniform_block_gl.cpp", "src/mbgl/gl/uniform_buffer_gl.cpp", "src/mbgl/gl/vertex_attribute_gl.cpp", "src/mbgl/shaders/gl/shader_info.cpp", @@ -1045,7 +1042,6 @@ MLN_DRAWABLES_GL_HEADERS = [ "include/mbgl/gl/drawable_gl.hpp", "include/mbgl/gl/drawable_gl_builder.hpp", "include/mbgl/gl/layer_group_gl.hpp", - "include/mbgl/gl/uniform_block_gl.hpp", "include/mbgl/gl/uniform_buffer_gl.hpp", "include/mbgl/gl/vertex_attribute_gl.hpp", "include/mbgl/gl/texture2d.hpp", @@ -1069,7 +1065,6 @@ MLN_DRAWABLES_MTL_SOURCE = [ "src/mbgl/mtl/texture2d.cpp", "src/mbgl/mtl/render_pass.cpp", "src/mbgl/mtl/tile_layer_group.cpp", - "src/mbgl/mtl/uniform_block.cpp", "src/mbgl/mtl/uniform_buffer.cpp", "src/mbgl/mtl/upload_pass.cpp", "src/mbgl/mtl/vertex_attribute.cpp", @@ -1109,7 +1104,6 @@ MLN_DRAWABLES_MTL_HEADERS = [ "include/mbgl/mtl/renderable_resource.hpp", "include/mbgl/mtl/texture2d.hpp", "include/mbgl/mtl/tile_layer_group.hpp", - "include/mbgl/mtl/uniform_block.hpp", "include/mbgl/mtl/uniform_buffer.hpp", "include/mbgl/mtl/upload_pass.hpp", "include/mbgl/mtl/vertex_attribute.hpp", diff --git a/include/mbgl/gfx/uniform_block.hpp b/include/mbgl/gfx/uniform_block.hpp deleted file mode 100644 index bbfd1f2fcb4..00000000000 --- a/include/mbgl/gfx/uniform_block.hpp +++ /dev/null @@ -1,114 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace mbgl { -namespace gfx { - -class UniformBuffer; -class UniformBlock; - -using UniqueUniformBlock = std::unique_ptr; - -/// @brief This class represents an uniform block -class UniformBlock { -public: - /// @brief Constructor - /// @param index_ - /// @param size_ - UniformBlock(int index_, std::size_t size_) - : index(index_), - size(size_) {} - UniformBlock(const UniformBlock&) = default; - UniformBlock(UniformBlock&& other) - : index(other.index), - size(other.size) {} - /// @brief Destructor - virtual ~UniformBlock() = default; - - /// @brief Retrieves the index of this uniform block - /// @return int - int getIndex() const { return index; } - - /// @brief Get the size of the uniform block - /// @return std::size_t - std::size_t getSize() const { return size; } - - /// @brief Binds the buffer - /// @param uniformBuffer - virtual void bindBuffer(const UniformBuffer& uniformBuffer) = 0; - - /// @brief Unbinds the uniform buffer - virtual void unbindBuffer() = 0; - -protected: - UniformBlock& operator=(const UniformBlock&) = default; - UniformBlock& operator=(UniformBlock&& other) { - index = other.index; - size = other.size; - return *this; - } - -protected: - int index; - std::size_t size; -}; - -/// Stores a collection of uniform blocks by id -class UniformBlockArray { -public: - /// @brief Constructor - UniformBlockArray() = default; - - /// @brief Move constructor - UniformBlockArray(UniformBlockArray&&); - - /// @brief Copy constructor. Would need to use the virtual assignment operator - UniformBlockArray(const UniformBlockArray&) = delete; - - /// @brief Destructor - virtual ~UniformBlockArray() = default; - - /// @brief Number of maximum allocated elements - std::size_t allocatedSize() const { return uniformBlockVector.size(); } - - /// @brief Get an uniform block element. - /// @return Pointer to the element on success, or null if the uniform block doesn't exists. - const std::unique_ptr& get(const size_t id) const; - - /// @brief Set a new uniform block element. - /// @param id - /// @param index - /// @param size - /// @return Pointer to the new element on success, or null if the uniform block already exists. - const std::unique_ptr& set(const size_t id, const size_t index, std::size_t size); - - /// @brief Move assignment operator - UniformBlockArray& operator=(UniformBlockArray&&); - - /// @brief Copy assignment operator - UniformBlockArray& operator=(const UniformBlockArray&); - - /// Do something with each block - template - void visit(Func f) { - std::for_each(uniformBlockVector.begin(), uniformBlockVector.end(), [&](const auto& block) { - if (block) { - f(*block); - } - }); - } - -protected: - virtual std::unique_ptr create(int index, std::size_t size) = 0; - virtual std::unique_ptr copy(const UniformBlock& uniformBlock) = 0; - -protected: - std::array uniformBlockVector; - static std::unique_ptr nullref; -}; - -} // namespace gfx -} // namespace mbgl diff --git a/include/mbgl/gfx/uniform_buffer.hpp b/include/mbgl/gfx/uniform_buffer.hpp index c76ce7c5385..a1d9023b304 100644 --- a/include/mbgl/gfx/uniform_buffer.hpp +++ b/include/mbgl/gfx/uniform_buffer.hpp @@ -41,17 +41,8 @@ class UniformBuffer { return *this; } -public: - bool getBindVertex() const { return bindVertex; } - void setBindVertex(bool value) { bindVertex = value; } - - bool getBindFragment() const { return bindFragment; } - void setBindFragment(bool value) { bindFragment = value; } - protected: std::size_t size; - bool bindVertex = false; - bool bindFragment = false; }; /// Stores a collection of uniform buffers by id @@ -72,20 +63,18 @@ class UniformBufferArray { /// Set a new uniform buffer element or replace the existing one. virtual const std::shared_ptr& set(const size_t id, - std::shared_ptr uniformBuffer, - bool bindVertex, - bool bindFragment); + std::shared_ptr uniformBuffer); /// Create and add a new buffer or update an existing one void createOrUpdate( - const size_t id, const std::vector& data, gfx::Context&, bool bindVertex, bool bindFragment); + const size_t id, const std::vector& data, gfx::Context&, bool persistent = false); virtual void createOrUpdate( - const size_t id, const void* data, std::size_t size, gfx::Context&, bool bindVertex, bool bindFragment); + const size_t id, const void* data, std::size_t size, gfx::Context&, bool persistent = false); template - void createOrUpdate(const size_t id, const T* data, gfx::Context& context, bool bindVertex, bool bindFragment) + void createOrUpdate(const size_t id, const T* data, gfx::Context& context, bool persistent = false) requires(!std::is_pointer_v) { - createOrUpdate(id, data, sizeof(T), context, bindVertex, bindFragment); + createOrUpdate(id, data, sizeof(T), context, persistent); } UniformBufferArray& operator=(UniformBufferArray&&); diff --git a/include/mbgl/gl/uniform_block_gl.hpp b/include/mbgl/gl/uniform_block_gl.hpp deleted file mode 100644 index c91cfc55f96..00000000000 --- a/include/mbgl/gl/uniform_block_gl.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { -namespace gl { - -class UniformBlockGL final : public gfx::UniformBlock { -public: - UniformBlockGL(int index_, std::size_t size_) - : UniformBlock(index_, size_) {} - UniformBlockGL(const UniformBlockGL& other) - : UniformBlock(other) {} - UniformBlockGL(UniformBlockGL&& other) - : UniformBlock(std::move(other)) {} - ~UniformBlockGL() override = default; - void bindBuffer(const gfx::UniformBuffer& uniformBuffer) override; - void unbindBuffer() override; -}; - -/// Stores a collection of uniform blocks by name -class UniformBlockArrayGL final : public gfx::UniformBlockArray { -public: - UniformBlockArrayGL() = default; - UniformBlockArrayGL(UniformBlockArrayGL&& other) - : UniformBlockArray(std::move(other)) {} - UniformBlockArrayGL(const UniformBlockArrayGL&) = delete; - - UniformBlockArrayGL& operator=(UniformBlockArrayGL&& other) { - UniformBlockArray::operator=(std::move(other)); - return *this; - } - UniformBlockArrayGL& operator=(const UniformBlockArrayGL& other) { - UniformBlockArray::operator=(other); - return *this; - } - -private: - std::unique_ptr create(int index, std::size_t size) override { - return std::make_unique(index, size); - } - std::unique_ptr copy(const gfx::UniformBlock& uniformBlocks) override { - return std::make_unique(static_cast(uniformBlocks)); - } -}; - -} // namespace gl -} // namespace mbgl diff --git a/include/mbgl/mtl/uniform_block.hpp b/include/mbgl/mtl/uniform_block.hpp deleted file mode 100644 index dcfef87f7c0..00000000000 --- a/include/mbgl/mtl/uniform_block.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { -namespace mtl { - -class UniformBlock final : public gfx::UniformBlock { -public: - UniformBlock(int index_, std::size_t size_) - : gfx::UniformBlock(index_, size_) {} - UniformBlock(const UniformBlock& other) - : gfx::UniformBlock(other) {} - UniformBlock(UniformBlock&& other) - : gfx::UniformBlock(std::move(other)) {} - ~UniformBlock() override = default; - void bindBuffer(const gfx::UniformBuffer& uniformBuffer) override; - void unbindBuffer() override; - - bool getBindVertex() const { return bindVertex; } - void setBindVertex(bool value) { bindVertex = value; } - - bool getBindFragment() const { return bindFragment; } - void setBindFragment(bool value) { bindFragment = value; } - -protected: - bool bindVertex = false; - bool bindFragment = false; -}; - -/// Stores a collection of uniform blocks by name -class UniformBlockArray final : public gfx::UniformBlockArray { -public: - UniformBlockArray() = default; - UniformBlockArray(UniformBlockArray&& other) - : gfx::UniformBlockArray(std::move(other)) {} - UniformBlockArray(const UniformBlockArray&) = delete; - - UniformBlockArray& operator=(UniformBlockArray&& other) { - gfx::UniformBlockArray::operator=(std::move(other)); - return *this; - } - UniformBlockArray& operator=(const UniformBlockArray& other) { - gfx::UniformBlockArray::operator=(other); - return *this; - } - -private: - std::unique_ptr create(int index, std::size_t size) override { - return std::make_unique(index, size); - } - std::unique_ptr copy(const gfx::UniformBlock& uniformBlocks) override { - return std::make_unique(static_cast(uniformBlocks)); - } -}; - -} // namespace mtl -} // namespace mbgl diff --git a/include/mbgl/shaders/gl/shader_program_gl.hpp b/include/mbgl/shaders/gl/shader_program_gl.hpp index 8e625fb7b89..cc4c778b648 100644 --- a/include/mbgl/shaders/gl/shader_program_gl.hpp +++ b/include/mbgl/shaders/gl/shader_program_gl.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -21,7 +20,6 @@ class ShaderProgramGL final : public gfx::ShaderProgramBase { ShaderProgramGL(UniqueProgram&& glProgram_); ShaderProgramGL(UniqueProgram&&, - UniformBlockArrayGL&& uniformBlocks, VertexAttributeArrayGL&& attributes, SamplerLocationArray&& samplerLocations); ShaderProgramGL(ShaderProgramGL&& other); @@ -42,21 +40,15 @@ class ShaderProgramGL final : public gfx::ShaderProgramBase { std::optional getSamplerLocation(const size_t id) const override; - const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; } - const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; } const gfx::VertexAttributeArray& getInstanceAttributes() const override { return instanceAttributes; } ProgramID getGLProgramID() const { return glProgram; } -protected: - gfx::UniformBlockArray& mutableUniformBlocks() override { return uniformBlocks; } - protected: UniqueProgram glProgram; - UniformBlockArrayGL uniformBlocks; VertexAttributeArrayGL vertexAttributes; VertexAttributeArrayGL instanceAttributes; SamplerLocationArray samplerLocations; diff --git a/include/mbgl/shaders/layer_ubo.hpp b/include/mbgl/shaders/layer_ubo.hpp index 3cbd0d09396..fd9b91a3e05 100644 --- a/include/mbgl/shaders/layer_ubo.hpp +++ b/include/mbgl/shaders/layer_ubo.hpp @@ -66,7 +66,13 @@ enum { #elif MLN_RENDER_BACKEND_VULKAN idGlobalPlatformParamsUBO, #endif - globalUBOCount, + globalUBOCount +}; + +enum { + idDrawableReservedVertexOnlyUBO = globalUBOCount, + idDrawableReservedFragmentOnlyUBO, + drawableReservedUBOCount }; #define MLN_UBO_CONSOLIDATION MLN_RENDER_BACKEND_METAL diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index 16234c5c985..3d307ecedc1 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -10,6 +10,12 @@ namespace shaders { #define BACKGROUND_SHADER_COMMON \ R"( +enum { + idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO, + idBackgroundPropsUBO = drawableReservedUBOCount, + backgroundUBOCount +}; + // // Background @@ -66,12 +72,6 @@ union BackgroundDrawableUnionUBO { BackgroundPatternDrawableUBO backgroundPatternDrawableUBO; }; -enum { - idBackgroundDrawableUBO = globalUBOCount, - idBackgroundPropsUBO, - backgroundUBOCount -}; - )" template <> @@ -80,8 +80,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -125,7 +124,6 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/circle.hpp b/include/mbgl/shaders/mtl/circle.hpp index fa10a2ef79b..2a95a763fe1 100644 --- a/include/mbgl/shaders/mtl/circle.hpp +++ b/include/mbgl/shaders/mtl/circle.hpp @@ -10,6 +10,12 @@ namespace shaders { #define CIRCLE_SHADER_PRELUDE \ R"( +enum { + idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO, + idCircleEvaluatedPropsUBO = drawableReservedUBOCount, + circleUBOCount +}; + struct alignas(16) CircleDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ float2 extrude_scale; @@ -45,12 +51,6 @@ struct alignas(16) CircleEvaluatedPropsUBO { }; static_assert(sizeof(CircleEvaluatedPropsUBO) == 4 * 16, "wrong size"); -enum { - idCircleDrawableUBO = globalUBOCount, - idCircleEvaluatedPropsUBO, - circleUBOCount -}; - )" template <> @@ -59,7 +59,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/clipping_mask.hpp b/include/mbgl/shaders/mtl/clipping_mask.hpp index 4899d302ec8..580c1ad9efd 100644 --- a/include/mbgl/shaders/mtl/clipping_mask.hpp +++ b/include/mbgl/shaders/mtl/clipping_mask.hpp @@ -22,6 +22,11 @@ static_assert(sizeof(ClipUBO) == 5 * 16); #include using namespace metal; +enum { + idClippingMaskUBO = idDrawableReservedVertexOnlyUBO, + clippingMaskUBOCount = drawableReservedUBOCount +}; + struct alignas(16) ClipUBO { /* 0 */ float4x4 matrix; /* 64 */ uint32_t stencil_ref; @@ -32,11 +37,6 @@ struct alignas(16) ClipUBO { }; static_assert(sizeof(ClipUBO) == 5 * 16, "wrong size"); -enum { - idClippingMaskUBO = globalUBOCount, - clippingMaskUBOCount -}; - )" template <> @@ -45,7 +45,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/collision.hpp b/include/mbgl/shaders/mtl/collision.hpp index a9e019067b9..ad62b6638af 100644 --- a/include/mbgl/shaders/mtl/collision.hpp +++ b/include/mbgl/shaders/mtl/collision.hpp @@ -10,6 +10,12 @@ namespace shaders { #define COLLISION_SHADER_COMMON \ R"( +enum { + idCollisionDrawableUBO = idDrawableReservedVertexOnlyUBO, + idCollisionTilePropsUBO = drawableReservedUBOCount, + collisionUBOCount +}; + struct alignas(16) CollisionDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ @@ -24,12 +30,6 @@ struct alignas(16) CollisionTilePropsUBO { }; static_assert(sizeof(CollisionTilePropsUBO) == 16, "wrong size"); -enum { - idCollisionDrawableUBO = globalUBOCount, - idCollisionTilePropsUBO, - collisionUBOCount -}; - )" template <> @@ -38,7 +38,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -112,7 +111,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/common.hpp b/include/mbgl/shaders/mtl/common.hpp index 94fcff58dff..4e20dc9313c 100644 --- a/include/mbgl/shaders/mtl/common.hpp +++ b/include/mbgl/shaders/mtl/common.hpp @@ -224,6 +224,12 @@ enum { globalUBOCount, }; +enum { + idDrawableReservedVertexOnlyUBO = globalUBOCount, + idDrawableReservedFragmentOnlyUBO, + drawableReservedUBOCount +}; + )"; } diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index 96c1a47c772..a52674c5e1b 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -10,6 +10,11 @@ namespace shaders { #define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \ R"( +enum { + idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, + customSymbolUBOCount = drawableReservedUBOCount +}; + struct alignas(16) CustomSymbolIconDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ float2 extrude_scale; @@ -26,11 +31,6 @@ struct alignas(16) CustomSymbolIconDrawableUBO { }; static_assert(sizeof(CustomSymbolIconParametersUBO) == 7 * 16, "wrong size"); -enum { - idCustomSymbolDrawableUBO = globalUBOCount, - customSymbolUBOCount -}; - )" template <> @@ -39,7 +39,6 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index 711da492339..5300da6ef0d 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -10,6 +10,11 @@ namespace shaders { #define DEBUG_SHADER_PRELUDE \ R"( +enum { + idDebugUBO = drawableReservedUBOCount, + debugUBOCount +}; + struct alignas(16) DebugUBO { /* 0 */ float4x4 matrix; /* 64 */ float4 color; @@ -21,11 +26,6 @@ struct alignas(16) DebugUBO { }; static_assert(sizeof(DebugUBO) == 6 * 16, "wrong size"); -enum { - idDebugUBO = globalUBOCount, - debugUBOCount -}; - )" template <> @@ -34,8 +34,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index de0bfd720ae..a46a2907066 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -10,6 +10,13 @@ namespace shaders { #define FILL_SHADER_COMMON \ R"( +enum { + idFillDrawableUBO = idDrawableReservedVertexOnlyUBO, + idFillTilePropsUBO = drawableReservedUBOCount, + idFillEvaluatedPropsUBO, + fillUBOCount +}; + // // Fill @@ -132,13 +139,6 @@ union FillTilePropsUnionUBO { FillOutlinePatternTilePropsUBO fillOutlinePatternTilePropsUBO; }; -enum { - idFillDrawableUBO = globalUBOCount, - idFillTilePropsUBO, - idFillEvaluatedPropsUBO, - fillUBOCount -}; - )" template <> @@ -147,8 +147,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -222,7 +221,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -300,7 +298,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -442,8 +439,7 @@ struct ShaderSource uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -597,7 +593,6 @@ struct ShaderSource uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index e651d9842d2..440df5ba361 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -10,6 +10,13 @@ namespace shaders { #define FILL_EXTRUSION_SHADER_COMMON \ R"( +enum { + idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO, + idFillExtrusionTilePropsUBO = drawableReservedUBOCount, + idFillExtrusionPropsUBO, + fillExtrusionUBOCount +}; + struct alignas(16) FillExtrusionDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ float2 pixel_coord_upper; @@ -55,13 +62,6 @@ struct alignas(16) FillExtrusionPropsUBO { }; static_assert(sizeof(FillExtrusionPropsUBO) == 5 * 16, "wrong size"); -enum { - idFillExtrusionDrawableUBO = globalUBOCount, - idFillExtrusionTilePropsUBO, - idFillExtrusionPropsUBO, - fillExtrusionUBOCount -}; - )" template <> @@ -70,7 +70,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -190,8 +189,7 @@ struct ShaderSource uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/heatmap.hpp b/include/mbgl/shaders/mtl/heatmap.hpp index 3b8caf6fa8c..81e4c25e4ba 100644 --- a/include/mbgl/shaders/mtl/heatmap.hpp +++ b/include/mbgl/shaders/mtl/heatmap.hpp @@ -10,6 +10,12 @@ namespace shaders { #define HEATMAP_SHADER_PRELUDE \ R"( +enum { + idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO, + idHeatmapEvaluatedPropsUBO = drawableReservedUBOCount, + heatmapUBOCount +}; + struct alignas(16) HeatmapDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ float extrude_scale; @@ -32,12 +38,6 @@ struct alignas(16) HeatmapEvaluatedPropsUBO { }; static_assert(sizeof(HeatmapEvaluatedPropsUBO) == 16, "wrong size"); -enum { - idHeatmapDrawableUBO = globalUBOCount, - idHeatmapEvaluatedPropsUBO, - heatmapUBOCount -}; - )" template <> @@ -46,7 +46,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/heatmap_texture.hpp b/include/mbgl/shaders/mtl/heatmap_texture.hpp index af3686eb344..e32b2fdb53d 100644 --- a/include/mbgl/shaders/mtl/heatmap_texture.hpp +++ b/include/mbgl/shaders/mtl/heatmap_texture.hpp @@ -10,6 +10,11 @@ namespace shaders { #define HEATMAP_TEXTURE_SHADER_PRELUDE \ R"( +enum { + idHeatmapTexturePropsUBO = drawableReservedUBOCount, + heatmapTextureUBOCount +}; + struct alignas(16) HeatmapTexturePropsUBO { /* 0 */ float4x4 matrix; /* 64 */ float opacity; @@ -20,11 +25,6 @@ struct alignas(16) HeatmapTexturePropsUBO { }; static_assert(sizeof(HeatmapTexturePropsUBO) == 5 * 16, "wrong size"); -enum { - idHeatmapTexturePropsUBO = globalUBOCount, - heatmapTextureUBOCount -}; - )" template <> @@ -33,7 +33,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/hillshade.hpp b/include/mbgl/shaders/mtl/hillshade.hpp index 34748b8de5d..39e5c74135e 100644 --- a/include/mbgl/shaders/mtl/hillshade.hpp +++ b/include/mbgl/shaders/mtl/hillshade.hpp @@ -10,6 +10,13 @@ namespace shaders { #define HILLSHADE_SHADER_PRELUDE \ R"( +enum { + idHillshadeDrawableUBO = idDrawableReservedVertexOnlyUBO, + idHillshadeTilePropsUBO = idDrawableReservedFragmentOnlyUBO, + idHillshadeEvaluatedPropsUBO = drawableReservedUBOCount, + hillshadeUBOCount +}; + struct alignas(16) HillshadeDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ @@ -32,13 +39,6 @@ struct alignas(16) HillshadeEvaluatedPropsUBO { }; static_assert(sizeof(HillshadeEvaluatedPropsUBO) == 3 * 16, "wrong size"); -enum { - idHillshadeDrawableUBO = globalUBOCount, - idHillshadeTilePropsUBO, - idHillshadeEvaluatedPropsUBO, - hillshadeUBOCount -}; - )" template <> @@ -47,7 +47,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index 7b3d8e41bde..450399b85a6 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -10,6 +10,12 @@ namespace shaders { #define HILLSHADE_PREPARE_SHADER_PRELUDE \ R"( +enum { + idHillshadePrepareDrawableUBO = idDrawableReservedVertexOnlyUBO, + idHillshadePrepareTilePropsUBO = drawableReservedUBOCount, + hillshadePrepareUBOCount +}; + struct alignas(16) HillshadePrepareDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ @@ -25,12 +31,6 @@ struct alignas(16) HillshadePrepareTilePropsUBO { }; static_assert(sizeof(HillshadePrepareTilePropsUBO) == 2 * 16, "wrong size"); -enum { - idHillshadePrepareDrawableUBO = globalUBOCount, - idHillshadePrepareTilePropsUBO, - hillshadePrepareUBOCount -}; - )" template <> @@ -39,8 +39,7 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index 5fb35d3aafe..f9656143ff0 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -10,6 +10,14 @@ namespace shaders { #define LINE_SHADER_COMMON \ R"( +enum { + idLineDrawableUBO = idDrawableReservedVertexOnlyUBO, + idLineTilePropsUBO = idDrawableReservedFragmentOnlyUBO, + idLineEvaluatedPropsUBO = drawableReservedUBOCount, + idLineExpressionUBO, + lineUBOCount +}; + // // Line @@ -163,14 +171,6 @@ union LineTilePropsUnionUBO { LineSDFTilePropsUBO lineSDFTilePropsUBO; }; -enum { - idLineDrawableUBO = globalUBOCount, - idLineTilePropsUBO, - idLineEvaluatedPropsUBO, - idLineExpressionUBO, - lineUBOCount -}; - )" template <> @@ -179,7 +179,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -358,7 +357,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -524,7 +522,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -760,8 +757,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/raster.hpp b/include/mbgl/shaders/mtl/raster.hpp index c16a548e177..22b1e995512 100644 --- a/include/mbgl/shaders/mtl/raster.hpp +++ b/include/mbgl/shaders/mtl/raster.hpp @@ -10,6 +10,12 @@ namespace shaders { #define RASTER_SHADER_PRELUDE \ R"( +enum { + idRasterDrawableUBO = idDrawableReservedVertexOnlyUBO, + idRasterEvaluatedPropsUBO = drawableReservedUBOCount, + rasterUBOCount +}; + struct alignas(16) RasterDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ @@ -34,12 +40,6 @@ struct alignas(16) RasterEvaluatedPropsUBO { }; static_assert(sizeof(RasterEvaluatedPropsUBO) == 4 * 16, "wrong size"); -enum { - idRasterDrawableUBO = globalUBOCount, - idRasterEvaluatedPropsUBO, - rasterUBOCount -}; - )" template <> @@ -48,7 +48,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/shader_group.hpp b/include/mbgl/shaders/mtl/shader_group.hpp index e6d96fa7f55..111332a0ca3 100644 --- a/include/mbgl/shaders/mtl/shader_group.hpp +++ b/include/mbgl/shaders/mtl/shader_group.hpp @@ -81,9 +81,6 @@ class ShaderGroup final : public ShaderGroupBase { for (const auto& attrib : ShaderClass::instanceAttributes) { shader->initInstanceAttribute(attrib); } - for (const auto& uniform : ShaderClass::uniforms) { - shader->initUniformBlock(uniform); - } for (const auto& texture : ShaderClass::textures) { shader->initTexture(texture); } diff --git a/include/mbgl/shaders/mtl/shader_program.hpp b/include/mbgl/shaders/mtl/shader_program.hpp index d67d8262cc9..95d92b1f484 100644 --- a/include/mbgl/shaders/mtl/shader_program.hpp +++ b/include/mbgl/shaders/mtl/shader_program.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -71,12 +70,8 @@ class ShaderProgram final : public gfx::ShaderProgramBase { const gfx::VertexAttributeArray& getInstanceAttributes() const override { return instanceAttributes; } - const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; } - gfx::UniformBlockArray& mutableUniformBlocks() override { return uniformBlocks; } - void initAttribute(const shaders::AttributeInfo&); void initInstanceAttribute(const shaders::AttributeInfo&); - void initUniformBlock(const shaders::UniformBlockInfo&); void initTexture(const shaders::TextureInfo&); protected: @@ -84,7 +79,6 @@ class ShaderProgram final : public gfx::ShaderProgramBase { RendererBackend& backend; MTLFunctionPtr vertexFunction; MTLFunctionPtr fragmentFunction; - UniformBlockArray uniformBlocks; VertexAttributeArray vertexAttributes; VertexAttributeArray instanceAttributes; std::array, shaders::maxTextureCountPerShader> textureBindings; diff --git a/include/mbgl/shaders/mtl/symbol.hpp b/include/mbgl/shaders/mtl/symbol.hpp index 9aa0a0fa780..496b3239a7a 100644 --- a/include/mbgl/shaders/mtl/symbol.hpp +++ b/include/mbgl/shaders/mtl/symbol.hpp @@ -10,6 +10,13 @@ namespace shaders { #define SYMBOL_SHADER_COMMON \ R"( +enum { + idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, + idSymbolTilePropsUBO = idDrawableReservedFragmentOnlyUBO, + idSymbolEvaluatedPropsUBO = drawableReservedUBOCount, + symbolUBOCount +}; + struct alignas(16) SymbolDrawableUBO { /* 0 */ float4x4 matrix; /* 64 */ float4x4 label_plane_matrix; @@ -64,13 +71,6 @@ struct alignas(16) SymbolEvaluatedPropsUBO { }; static_assert(sizeof(SymbolEvaluatedPropsUBO) == 6 * 16, "wrong size"); -enum { - idSymbolDrawableUBO = globalUBOCount, - idSymbolTilePropsUBO, - idSymbolEvaluatedPropsUBO, - symbolUBOCount -}; - )" template <> @@ -79,8 +79,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -216,7 +215,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -424,8 +422,7 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/widevector.hpp b/include/mbgl/shaders/mtl/widevector.hpp index 200171ff53e..ba18276c5c6 100644 --- a/include/mbgl/shaders/mtl/widevector.hpp +++ b/include/mbgl/shaders/mtl/widevector.hpp @@ -11,8 +11,8 @@ namespace shaders { R"( enum { - idWideVectorUniformsUBO = globalUBOCount, - idWideVectorUniformWideVecUBO, + idWideVectorUniformsUBO = idDrawableReservedVertexOnlyUBO, + idWideVectorUniformWideVecUBO = drawableReservedUBOCount, wideVectorUBOCount }; @@ -24,7 +24,6 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexTri_wideVecPerf"; static constexpr auto fragmentMainFunction = "fragmentTri_wideVecPerf"; - static const std::array uniforms; static const std::array attributes; static const std::array instanceAttributes; static const std::array textures; diff --git a/include/mbgl/shaders/shader_defines.hpp b/include/mbgl/shaders/shader_defines.hpp index 4efce8bf8fd..692c688a188 100644 --- a/include/mbgl/shaders/shader_defines.hpp +++ b/include/mbgl/shaders/shader_defines.hpp @@ -10,94 +10,94 @@ namespace shaders { // drawable UBOs enum { - idBackgroundDrawableUBO = globalUBOCount, - backgroundDrawableUBOCount + idBackgroundDrawableUBO = idDrawableReservedVertexOnlyUBO, + backgroundDrawableUBOCount = drawableReservedUBOCount }; enum { - idCircleDrawableUBO = globalUBOCount, - circleDrawableUBOCount + idCircleDrawableUBO = idDrawableReservedVertexOnlyUBO, + circleDrawableUBOCount = drawableReservedUBOCount }; enum { - idClippingMaskUBO = globalUBOCount, - clippingMaskDrawableUBOCount + idClippingMaskUBO = idDrawableReservedVertexOnlyUBO, + clippingMaskDrawableUBOCount = drawableReservedUBOCount }; enum { - idCollisionDrawableUBO = globalUBOCount, - idCollisionTilePropsUBO, + idCollisionDrawableUBO = idDrawableReservedVertexOnlyUBO, + idCollisionTilePropsUBO = drawableReservedUBOCount, collisionDrawableUBOCount }; enum { - idCustomSymbolDrawableUBO = globalUBOCount, - customSymbolDrawableUBOCount + idCustomSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, + customSymbolDrawableUBOCount = drawableReservedUBOCount }; enum { - idDebugUBO = globalUBOCount, + idDebugUBO = drawableReservedUBOCount, debugDrawableUBOCount }; enum { - idFillDrawableUBO = globalUBOCount, - idFillTilePropsUBO, + idFillDrawableUBO = idDrawableReservedVertexOnlyUBO, + idFillTilePropsUBO = drawableReservedUBOCount, fillDrawableUBOCount }; enum { - idFillExtrusionDrawableUBO = globalUBOCount, - idFillExtrusionTilePropsUBO, + idFillExtrusionDrawableUBO = idDrawableReservedVertexOnlyUBO, + idFillExtrusionTilePropsUBO = drawableReservedUBOCount, fillExtrusionDrawableUBOCount }; enum { - idHeatmapDrawableUBO = globalUBOCount, - heatmapDrawableUBOCount + idHeatmapDrawableUBO = idDrawableReservedVertexOnlyUBO, + heatmapDrawableUBOCount = drawableReservedUBOCount }; enum { - heatmapTextureDrawableUBOCount = globalUBOCount + heatmapTextureDrawableUBOCount = drawableReservedUBOCount }; enum { - idHillshadeDrawableUBO = globalUBOCount, - idHillshadeTilePropsUBO, - hillshadeDrawableUBOCount + idHillshadeDrawableUBO = idDrawableReservedVertexOnlyUBO, + idHillshadeTilePropsUBO = idDrawableReservedFragmentOnlyUBO, + hillshadeDrawableUBOCount = drawableReservedUBOCount }; enum { - idHillshadePrepareDrawableUBO = globalUBOCount, - idHillshadePrepareTilePropsUBO, + idHillshadePrepareDrawableUBO = idDrawableReservedVertexOnlyUBO, + idHillshadePrepareTilePropsUBO = drawableReservedUBOCount, hillshadePrepareDrawableUBOCount }; enum { - idLineDrawableUBO = globalUBOCount, - idLineTilePropsUBO, - lineDrawableUBOCount + idLineDrawableUBO = idDrawableReservedVertexOnlyUBO, + idLineTilePropsUBO = idDrawableReservedFragmentOnlyUBO, + lineDrawableUBOCount = drawableReservedUBOCount }; enum { - idLocationIndicatorDrawableUBO = globalUBOCount, + idLocationIndicatorDrawableUBO = drawableReservedUBOCount, locationIndicatorDrawableUBOCount }; enum { - idRasterDrawableUBO = globalUBOCount, - rasterDrawableUBOCount + idRasterDrawableUBO = idDrawableReservedVertexOnlyUBO, + rasterDrawableUBOCount = drawableReservedUBOCount }; enum { - idSymbolDrawableUBO = globalUBOCount, - idSymbolTilePropsUBO, - symbolDrawableUBOCount + idSymbolDrawableUBO = idDrawableReservedVertexOnlyUBO, + idSymbolTilePropsUBO = idDrawableReservedFragmentOnlyUBO, + symbolDrawableUBOCount = drawableReservedUBOCount }; enum { - idWideVectorUniformsUBO = globalUBOCount, - idWideVectorUniformWideVecUBO, + idWideVectorUniformsUBO = idDrawableReservedVertexOnlyUBO, + idWideVectorUniformWideVecUBO = drawableReservedUBOCount, wideVectorDrawableUBOCount }; diff --git a/include/mbgl/shaders/shader_program_base.hpp b/include/mbgl/shaders/shader_program_base.hpp index 7c4e4b678d7..b2716058635 100644 --- a/include/mbgl/shaders/shader_program_base.hpp +++ b/include/mbgl/shaders/shader_program_base.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -34,18 +33,12 @@ class ShaderProgramBase : public gfx::Shader { /// @param name uniform name virtual std::optional getSamplerLocation(const size_t) const = 0; - /// Get the available uniform blocks attached to this shader - virtual const gfx::UniformBlockArray& getUniformBlocks() const = 0; - /// Get the available vertex attributes and their default values virtual const gfx::VertexAttributeArray& getVertexAttributes() const = 0; /// Get the available instance attributes and their default values virtual const gfx::VertexAttributeArray& getInstanceAttributes() const = 0; -protected: - virtual gfx::UniformBlockArray& mutableUniformBlocks() = 0; - protected: util::SimpleIdentity shaderProgramID; }; diff --git a/include/mbgl/shaders/vulkan/background.hpp b/include/mbgl/shaders/vulkan/background.hpp index 81989d916da..ec9b6ef0284 100644 --- a/include/mbgl/shaders/vulkan/background.hpp +++ b/include/mbgl/shaders/vulkan/background.hpp @@ -6,20 +6,27 @@ namespace mbgl { namespace shaders { +#define BACKGROUND_SHADER_COMMON \ + R"( + +#define idBackgroundDrawableUBO idDrawableReservedVertexOnlyUBO +#define idBackgroundPropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "BackgroundShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = BACKGROUND_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform BackgroundDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idBackgroundDrawableUBO) uniform BackgroundDrawableUBO { mat4 matrix; } drawable; @@ -29,10 +36,10 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = BACKGROUND_SHADER_COMMON R"( layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idBackgroundPropsUBO) uniform BackgroundPropsUBO { vec4 color; float opacity; float pad1; @@ -56,16 +63,14 @@ template <> struct ShaderSource { static constexpr const char* name = "BackgroundPatternShader"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( - + static constexpr auto vertex = BACKGROUND_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform BackgroundPatternDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idBackgroundDrawableUBO) uniform BackgroundPatternDrawableUBO { mat4 matrix; vec2 pixel_coord_upper; vec2 pixel_coord_lower; @@ -75,7 +80,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform BackgroundPatternDrawa float pad3; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idBackgroundPropsUBO) uniform BackgroundPatternPropsUBO { vec2 pattern_tl_a; vec2 pattern_br_a; vec2 pattern_tl_b; @@ -109,13 +114,13 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = BACKGROUND_SHADER_COMMON R"( layout(location = 0) in vec2 frag_pos_a; layout(location = 1) in vec2 frag_pos_b; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform BackgroundPatternLayerUBO { +layout(set = LAYER_SET_INDEX, binding = idBackgroundPropsUBO) uniform BackgroundPatternLayerUBO { vec2 pattern_tl_a; vec2 pattern_br_a; vec2 pattern_tl_b; diff --git a/include/mbgl/shaders/vulkan/circle.hpp b/include/mbgl/shaders/vulkan/circle.hpp index 7d7198f3a61..b96c2689273 100644 --- a/include/mbgl/shaders/vulkan/circle.hpp +++ b/include/mbgl/shaders/vulkan/circle.hpp @@ -6,16 +6,23 @@ namespace mbgl { namespace shaders { +#define CIRCLE_SHADER_PRELUDE \ + R"( + +#define idCircleDrawableUBO idDrawableReservedVertexOnlyUBO +#define idCircleEvaluatedPropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "CircleShader"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = CIRCLE_SHADER_PRELUDE R"( layout(location = 0) in ivec2 in_position; @@ -47,7 +54,7 @@ layout(location = 6) in vec2 in_stroke_width; layout(location = 7) in vec2 in_stroke_opacity; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CircleDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCircleDrawableUBO) uniform CircleDrawableUBO { mat4 matrix; vec2 extrude_scale; // Interpolations @@ -63,7 +70,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CircleDrawableUBO { float pad3; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idCircleEvaluatedPropsUBO) uniform CircleEvaluatedPropsUBO { vec4 color; vec4 stroke_color; float radius; @@ -188,7 +195,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = CIRCLE_SHADER_PRELUDE R"( layout(location = 0) in vec2 frag_extrude; layout(location = 1) in float frag_antialiasblur; @@ -223,7 +230,7 @@ layout(location = 8) in lowp float frag_stroke_opacity; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform CircleEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idCircleEvaluatedPropsUBO) uniform CircleEvaluatedPropsUBO { vec4 color; vec4 stroke_color; float radius; diff --git a/include/mbgl/shaders/vulkan/clipping_mask.hpp b/include/mbgl/shaders/vulkan/clipping_mask.hpp index d5b3ce9f171..3b3dd7e4408 100644 --- a/include/mbgl/shaders/vulkan/clipping_mask.hpp +++ b/include/mbgl/shaders/vulkan/clipping_mask.hpp @@ -16,7 +16,6 @@ template <> struct ShaderSource { static constexpr const char* name = "ClippingMaskProgram"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/vulkan/collision.hpp b/include/mbgl/shaders/vulkan/collision.hpp index 3ebdf230f7a..b5bdda8387c 100644 --- a/include/mbgl/shaders/vulkan/collision.hpp +++ b/include/mbgl/shaders/vulkan/collision.hpp @@ -6,16 +6,23 @@ namespace mbgl { namespace shaders { +#define COLLISION_SHADER_COMMON \ + R"( + +#define idCollisionDrawableUBO idDrawableReservedVertexOnlyUBO +#define idCollisionTilePropsUBO drawableReservedUBOCount + +)" + template <> struct ShaderSource { static constexpr const char* name = "CollisionBoxShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = COLLISION_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec2 in_anchor_position; @@ -23,11 +30,11 @@ layout(location = 2) in ivec2 in_extrude; layout(location = 3) in uvec2 in_placed; layout(location = 4) in vec2 in_shift; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionDrawableUBO) uniform CollisionDrawableUBO { mat4 matrix; } drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CollisionTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionTilePropsUBO) uniform CollisionTilePropsUBO { vec2 extrude_scale; float overscale_factor; float pad1; @@ -54,7 +61,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = COLLISION_SHADER_COMMON R"( layout(location = 0) in float frag_placed; layout(location = 1) in float frag_notUsed; @@ -87,23 +94,22 @@ template <> struct ShaderSource { static constexpr const char* name = "CollisionCircleShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = COLLISION_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec2 in_anchor_position; layout(location = 2) in ivec2 in_extrude; layout(location = 3) in uvec2 in_placed; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CollisionDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionDrawableUBO) uniform CollisionDrawableUBO { mat4 matrix; } drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CollisionTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionTilePropsUBO) uniform CollisionTilePropsUBO { vec2 extrude_scale; float overscale_factor; float pad1; @@ -137,7 +143,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = COLLISION_SHADER_COMMON R"( layout(location = 0) in float frag_placed; layout(location = 1) in float frag_notUsed; @@ -147,7 +153,7 @@ layout(location = 4) in vec2 frag_extrude_scale; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform CollisionTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCollisionTilePropsUBO) uniform CollisionTilePropsUBO { vec2 extrude_scale; float overscale_factor; float pad1; diff --git a/include/mbgl/shaders/vulkan/common.hpp b/include/mbgl/shaders/vulkan/common.hpp index 10c395d245d..0f6ba911a39 100644 --- a/include/mbgl/shaders/vulkan/common.hpp +++ b/include/mbgl/shaders/vulkan/common.hpp @@ -72,6 +72,11 @@ vec2 get_pattern_pos(const vec2 pixel_coord_upper, const vec2 pixel_coord_lower, #define DRAWABLE_UBO_SET_INDEX 2 #define DRAWABLE_IMAGE_SET_INDEX 3 +#define idDrawableReservedVertexOnlyUBO 0 +#define idDrawableReservedFragmentOnlyUBO 1 +#define drawableReservedUBOCount 2 +#define layerUBOStartId 0 + layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO { vec2 pattern_atlas_texsize; vec2 units_to_pixels; @@ -110,6 +115,11 @@ void applySurfaceTransform() { #define DRAWABLE_UBO_SET_INDEX 2 #define DRAWABLE_IMAGE_SET_INDEX 3 +#define idDrawableReservedVertexOnlyUBO 0 +#define idDrawableReservedFragmentOnlyUBO 1 +#define drawableReservedUBOCount 2 +#define layerUBOStartId 0 + layout(set = GLOBAL_SET_INDEX, binding = 0) uniform GlobalPaintParamsUBO { vec2 pattern_atlas_texsize; vec2 units_to_pixels; diff --git a/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp b/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp index a3030b8822d..ce0e3763877 100644 --- a/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp @@ -6,21 +6,27 @@ namespace mbgl { namespace shaders { +#define CUSTOM_SYMBOL_ICON_SHADER_PRELUDE \ + R"( + +#define idCustomSymbolDrawableUBO idDrawableReservedVertexOnlyUBO + +)" + template <> struct ShaderSource { static constexpr const char* name = "CustomSymbolIconShader"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"( layout(location = 0) in vec2 in_position; layout(location = 1) in vec2 in_tex; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform CustomSymbolIconDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idCustomSymbolDrawableUBO) uniform CustomSymbolIconDrawableUBO { mat4 matrix; vec2 extrude_scale; vec2 anchor; @@ -79,7 +85,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = CUSTOM_SYMBOL_ICON_SHADER_PRELUDE R"( layout(location = 0) in vec2 frag_tex; layout(location = 0) out vec4 out_color; diff --git a/include/mbgl/shaders/vulkan/debug.hpp b/include/mbgl/shaders/vulkan/debug.hpp index 992bf6745ed..9c36febd777 100644 --- a/include/mbgl/shaders/vulkan/debug.hpp +++ b/include/mbgl/shaders/vulkan/debug.hpp @@ -6,20 +6,26 @@ namespace mbgl { namespace shaders { +#define DEBUG_SHADER_PRELUDE \ + R"( + +#define idDebugUBO drawableReservedUBOCount + +)" + template <> struct ShaderSource { static constexpr const char* name = "DebugShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = DEBUG_SHADER_PRELUDE R"( layout(location = 0) in ivec2 in_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform DebugUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idDebugUBO) uniform DebugUBO { mat4 matrix; vec4 color; float overlay_scale; @@ -41,11 +47,11 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = DEBUG_SHADER_PRELUDE R"( layout(location = 0) in vec2 frag_uv; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform DebugUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idDebugUBO) uniform DebugUBO { mat4 matrix; vec4 color; float overlay_scale; diff --git a/include/mbgl/shaders/vulkan/fill.hpp b/include/mbgl/shaders/vulkan/fill.hpp index 93f71950593..4920915449a 100644 --- a/include/mbgl/shaders/vulkan/fill.hpp +++ b/include/mbgl/shaders/vulkan/fill.hpp @@ -6,16 +6,24 @@ namespace mbgl { namespace shaders { +#define FILL_SHADER_COMMON \ + R"( + +#define idFillDrawableUBO idDrawableReservedVertexOnlyUBO +#define idFillTilePropsUBO drawableReservedUBOCount +#define idFillEvaluatedPropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "FillShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = FILL_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; @@ -27,7 +35,7 @@ layout(location = 1) in vec4 in_color; layout(location = 2) in vec2 in_opacity; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillDrawableUBO) uniform FillDrawableUBO { mat4 matrix; // Interpolations float color_t; @@ -59,7 +67,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = FILL_SHADER_COMMON R"( #if !defined(HAS_UNIFORM_u_color) layout(location = 0) in vec4 frag_color; @@ -71,7 +79,7 @@ layout(location = 1) in lowp float frag_opacity; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillEvaluatedPropsUBO) uniform FillEvaluatedPropsUBO { vec4 color; vec4 outline_color; float opacity; @@ -103,12 +111,11 @@ template <> struct ShaderSource { static constexpr const char* name = "FillOutlineShader"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = FILL_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; @@ -120,7 +127,7 @@ layout(location = 1) in vec4 in_color; layout(location = 2) in vec2 in_opacity; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillOutlineDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillDrawableUBO) uniform FillOutlineDrawableUBO { mat4 matrix; // Interpolations float outline_color_t; @@ -156,7 +163,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = FILL_SHADER_COMMON R"( #if !defined(HAS_UNIFORM_u_outline_color) layout(location = 0) in vec4 frag_color; @@ -170,7 +177,7 @@ layout(location = 2) in vec2 frag_position; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillEvaluatedPropsUBO) uniform FillEvaluatedPropsUBO { vec4 color; vec4 outline_color; float opacity; @@ -209,12 +216,11 @@ template <> struct ShaderSource { static constexpr const char* name = "FillPatternShader"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = FILL_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; @@ -230,7 +236,7 @@ layout(location = 2) in mediump uvec4 in_pattern_to; layout(location = 3) in vec2 in_opacity; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillPatternDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillDrawableUBO) uniform FillPatternDrawableUBO { mat4 matrix; vec2 pixel_coord_upper; vec2 pixel_coord_lower; @@ -241,7 +247,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillPatternDrawableUBO float opacity_t; } drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillPatternTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillTilePropsUBO) uniform FillPatternTilePropsUBO { vec4 pattern_from; vec4 pattern_to; vec2 texsize; @@ -249,7 +255,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillPatternTilePropsUB float pad2; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillEvaluatedPropsUBO) uniform FillEvaluatedPropsUBO { vec4 color; vec4 outline_color; float opacity; @@ -312,7 +318,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = FILL_SHADER_COMMON R"( layout(location = 0) in vec2 frag_pos_a; layout(location = 1) in vec2 frag_pos_b; @@ -331,7 +337,7 @@ layout(location = 4) in lowp float frag_opacity; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillPatternTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillTilePropsUBO) uniform FillPatternTilePropsUBO { vec4 pattern_from; vec4 pattern_to; vec2 texsize; @@ -339,7 +345,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillPatternTilePropsUB float pad2; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillEvaluatedPropsUBO) uniform FillEvaluatedPropsUBO { vec4 color; vec4 outline_color; float opacity; @@ -397,12 +403,11 @@ template <> struct ShaderSource { static constexpr const char* name = "FillOutlinePatternShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = FILL_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; @@ -418,7 +423,7 @@ layout(location = 2) in mediump uvec4 in_pattern_to; layout(location = 3) in vec2 in_opacity; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillOutlinePatternDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillDrawableUBO) uniform FillOutlinePatternDrawableUBO { mat4 matrix; vec2 pixel_coord_upper; vec2 pixel_coord_lower; @@ -429,7 +434,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillOutlinePatternDraw float opacity_t; } drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillOutlinePatternTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillTilePropsUBO) uniform FillOutlinePatternTilePropsUBO { vec4 pattern_from; vec4 pattern_to; vec2 texsize; @@ -437,7 +442,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillOutlinePatternTile float pad2; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillEvaluatedPropsUBO) uniform FillEvaluatedPropsUBO { vec4 color; vec4 outline_color; float opacity; @@ -503,7 +508,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = FILL_SHADER_COMMON R"( layout(location = 0) in vec2 frag_pos_a; layout(location = 1) in vec2 frag_pos_b; @@ -523,7 +528,7 @@ layout(location = 5) in lowp float frag_opacity; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillOutlinePatternTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillTilePropsUBO) uniform FillOutlinePatternTilePropsUBO { vec4 pattern_from; vec4 pattern_to; vec2 texsize; @@ -531,7 +536,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillOutlinePatternTile float pad2; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillEvaluatedPropsUBO) uniform FillEvaluatedPropsUBO { vec4 color; vec4 outline_color; float opacity; @@ -592,17 +597,16 @@ template <> struct ShaderSource { static constexpr const char* name = "FillOutlineTriangulatedShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = FILL_SHADER_COMMON R"( layout(location = 0) in ivec2 in_pos_normal; layout(location = 1) in uvec4 in_data; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillOutlineTriangulatedDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillDrawableUBO) uniform FillOutlineTriangulatedDrawableUBO { mat4 matrix; float ratio; float pad1, @@ -652,7 +656,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = FILL_SHADER_COMMON R"( layout(location = 0) in float frag_width2; layout(location = 1) in vec2 frag_normal; @@ -660,7 +664,7 @@ layout(location = 2) in float frag_gamma_scale; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillEvaluatedPropsUBO) uniform FillEvaluatedPropsUBO { vec4 color; vec4 outline_color; float opacity; diff --git a/include/mbgl/shaders/vulkan/fill_extrusion.hpp b/include/mbgl/shaders/vulkan/fill_extrusion.hpp index 9e43a5f87e2..c4f82e32392 100644 --- a/include/mbgl/shaders/vulkan/fill_extrusion.hpp +++ b/include/mbgl/shaders/vulkan/fill_extrusion.hpp @@ -6,16 +6,24 @@ namespace mbgl { namespace shaders { +#define FILL_EXTRUSION_SHADER_COMMON \ + R"( + +#define idFillExtrusionDrawableUBO idDrawableReservedVertexOnlyUBO +#define idFillExtrusionTilePropsUBO drawableReservedUBOCount +#define idFillExtrusionPropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "FillExtrusionShader"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = FILL_EXTRUSION_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec4 in_normal_ed; @@ -32,7 +40,7 @@ layout(location = 3) in vec2 in_base; layout(location = 4) in vec2 in_height; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillExtrusionDrawableUBO) uniform FillExtrusionDrawableUBO { mat4 matrix; vec2 pixel_coord_upper; vec2 pixel_coord_lower; @@ -47,7 +55,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableU float pad1; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillExtrusionPropsUBO) uniform FillExtrusionPropsUBO { vec4 color; vec4 light_color_pad; vec4 light_position_base; @@ -134,7 +142,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = FILL_EXTRUSION_SHADER_COMMON R"( layout(location = 0) in vec4 frag_color; layout(location = 0) out vec4 out_color; @@ -149,12 +157,11 @@ template <> struct ShaderSource { static constexpr const char* name = "FillExtrusionPatternShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = FILL_EXTRUSION_SHADER_COMMON R"( layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec4 in_normal_ed; @@ -175,7 +182,7 @@ layout(location = 4) in uvec4 in_pattern_from; layout(location = 5) in uvec4 in_pattern_to; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillExtrusionDrawableUBO) uniform FillExtrusionDrawableUBO { mat4 matrix; vec2 pixel_coord_upper; vec2 pixel_coord_lower; @@ -190,7 +197,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform FillExtrusionDrawableU float pad1; } drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillExtrusionTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillExtrusionTilePropsUBO) uniform FillExtrusionTilePropsUBO { vec4 pattern_from; vec4 pattern_to; vec2 texsize; @@ -198,7 +205,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillExtrusionTileProps float pad2; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillExtrusionPropsUBO) uniform FillExtrusionPropsUBO { vec4 color; vec4 light_color_pad; vec4 light_position_base; @@ -311,7 +318,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = FILL_EXTRUSION_SHADER_COMMON R"( layout(location = 0) in mediump vec4 frag_lighting; layout(location = 1) in mediump vec2 frag_pos_a; @@ -327,7 +334,7 @@ layout(location = 4) in mediump vec4 frag_pattern_to; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillExtrusionTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idFillExtrusionTilePropsUBO) uniform FillExtrusionTilePropsUBO { vec4 pattern_from; vec4 pattern_to; vec2 texsize; @@ -335,7 +342,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform FillExtrusionTileProps float pad2; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform FillExtrusionPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idFillExtrusionPropsUBO) uniform FillExtrusionPropsUBO { vec4 color; vec4 light_color_pad; vec4 light_position_base; diff --git a/include/mbgl/shaders/vulkan/heatmap.hpp b/include/mbgl/shaders/vulkan/heatmap.hpp index da11f000092..d513487877b 100644 --- a/include/mbgl/shaders/vulkan/heatmap.hpp +++ b/include/mbgl/shaders/vulkan/heatmap.hpp @@ -6,16 +6,23 @@ namespace mbgl { namespace shaders { +#define HEATMAP_SHADER_PRELUDE \ + R"( + +#define idHeatmapDrawableUBO idDrawableReservedVertexOnlyUBO +#define idHeatmapEvaluatedPropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "HeatmapShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = HEATMAP_SHADER_PRELUDE R"( // Effective "0" in the kernel density texture to adjust the kernel size to; // this empirically chosen number minimizes artifacts on overlapping kernels @@ -35,7 +42,7 @@ layout(location = 1) in vec2 in_weight; layout(location = 2) in vec2 in_radius; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HeatmapDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idHeatmapDrawableUBO) uniform HeatmapDrawableUBO { mat4 matrix; float extrude_scale; // Interpolations @@ -44,7 +51,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HeatmapDrawableUBO { float pad1; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idHeatmapEvaluatedPropsUBO) uniform HeatmapEvaluatedPropsUBO { float weight; float radius; float intensity; @@ -101,7 +108,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = HEATMAP_SHADER_PRELUDE R"( // Gaussian kernel coefficient: 1 / sqrt(2 * PI) #define GAUSS_COEF 0.3989422804014327 @@ -111,7 +118,7 @@ layout(location = 1) in lowp vec2 frag_extrude; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idHeatmapEvaluatedPropsUBO) uniform HeatmapEvaluatedPropsUBO { float weight; float radius; float intensity; diff --git a/include/mbgl/shaders/vulkan/heatmap_texture.hpp b/include/mbgl/shaders/vulkan/heatmap_texture.hpp index 59dae6baf92..60c1439e1d6 100644 --- a/include/mbgl/shaders/vulkan/heatmap_texture.hpp +++ b/include/mbgl/shaders/vulkan/heatmap_texture.hpp @@ -6,20 +6,26 @@ namespace mbgl { namespace shaders { +#define HEATMAP_TEXTURE_SHADER_PRELUDE \ + R"( + +#define idHeatmapTexturePropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "HeatmapTextureShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = HEATMAP_TEXTURE_SHADER_PRELUDE R"( layout(location = 0) in ivec2 in_position; -layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapTexturePropsUBO { +layout(set = LAYER_SET_INDEX, binding = idHeatmapTexturePropsUBO) uniform HeatmapTexturePropsUBO { mat4 matrix; float opacity; float pad1; @@ -38,12 +44,12 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = HEATMAP_TEXTURE_SHADER_PRELUDE R"( layout(location = 0) in vec2 frag_position; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform HeatmapTexturePropsUBO { +layout(set = LAYER_SET_INDEX, binding = idHeatmapTexturePropsUBO) uniform HeatmapTexturePropsUBO { mat4 matrix; float opacity; float pad1; diff --git a/include/mbgl/shaders/vulkan/hillshade.hpp b/include/mbgl/shaders/vulkan/hillshade.hpp index ca1fe8da105..499650ee988 100644 --- a/include/mbgl/shaders/vulkan/hillshade.hpp +++ b/include/mbgl/shaders/vulkan/hillshade.hpp @@ -6,21 +6,29 @@ namespace mbgl { namespace shaders { +#define HILLSHADE_SHADER_PRELUDE \ + R"( + +#define idHillshadeDrawableUBO idDrawableReservedVertexOnlyUBO +#define idHillshadeTilePropsUBO idDrawableReservedFragmentOnlyUBO +#define idHillshadeEvaluatedPropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "HillshadeShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = HILLSHADE_SHADER_PRELUDE R"( layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec2 in_texture_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HillshadeDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idHillshadeDrawableUBO) uniform HillshadeDrawableUBO { mat4 matrix; } drawable; @@ -36,17 +44,17 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = HILLSHADE_SHADER_PRELUDE R"( layout(location = 0) in vec2 frag_position; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform HillshadeTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idHillshadeTilePropsUBO) uniform HillshadeTilePropsUBO { vec2 latrange; vec2 light; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform HillshadeEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idHillshadeEvaluatedPropsUBO) uniform HillshadeEvaluatedPropsUBO { vec4 highlight; vec4 shadow; vec4 accent; diff --git a/include/mbgl/shaders/vulkan/hillshade_prepare.hpp b/include/mbgl/shaders/vulkan/hillshade_prepare.hpp index 872c48690c2..4b079a07596 100644 --- a/include/mbgl/shaders/vulkan/hillshade_prepare.hpp +++ b/include/mbgl/shaders/vulkan/hillshade_prepare.hpp @@ -6,25 +6,32 @@ namespace mbgl { namespace shaders { +#define HILLSHADE_PREPARE_SHADER_PRELUDE \ + R"( + +#define idHillshadePrepareDrawableUBO idDrawableReservedVertexOnlyUBO +#define idHillshadePrepareTilePropsUBO drawableReservedUBOCount + +)" + template <> struct ShaderSource { static constexpr const char* name = "HillshadePrepareShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = HILLSHADE_PREPARE_SHADER_PRELUDE R"( layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec2 in_texture_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform HillshadePrepareDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idHillshadePrepareDrawableUBO) uniform HillshadePrepareDrawableUBO { mat4 matrix; } drawable; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform HillshadePrepareTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idHillshadePrepareTilePropsUBO) uniform HillshadePrepareTilePropsUBO { vec4 unpack; vec2 dimension; float zoom; @@ -44,12 +51,12 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = HILLSHADE_PREPARE_SHADER_PRELUDE R"( layout(location = 0) in vec2 frag_position; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform HillshadePrepareTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idHillshadePrepareTilePropsUBO) uniform HillshadePrepareTilePropsUBO { vec4 unpack; vec2 dimension; float zoom; diff --git a/include/mbgl/shaders/vulkan/line.hpp b/include/mbgl/shaders/vulkan/line.hpp index 6dddd3fb9c6..f47893a0f45 100644 --- a/include/mbgl/shaders/vulkan/line.hpp +++ b/include/mbgl/shaders/vulkan/line.hpp @@ -6,16 +6,24 @@ namespace mbgl { namespace shaders { +#define LINE_SHADER_COMMON \ + R"( + +#define idLineDrawableUBO idDrawableReservedVertexOnlyUBO +#define idLineTilePropsUBO idDrawableReservedFragmentOnlyUBO +#define idLineEvaluatedPropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "LineShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = LINE_SHADER_COMMON R"( layout(location = 0) in ivec2 in_pos_normal; layout(location = 1) in uvec4 in_data; @@ -44,7 +52,7 @@ layout(location = 6) in vec2 in_offset; layout(location = 7) in vec2 in_width; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineDrawableUBO { mat4 matrix; mediump float ratio; // Interpolations @@ -57,7 +65,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineDrawableUBO { float pad1; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; float blur; float opacity; @@ -163,7 +171,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = LINE_SHADER_COMMON R"( layout(location = 0) in lowp vec2 frag_normal; layout(location = 1) in lowp vec2 frag_width2; @@ -183,7 +191,7 @@ layout(location = 5) in lowp float frag_opacity; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; float blur; float opacity; @@ -238,12 +246,11 @@ template <> struct ShaderSource { static constexpr const char* name = "LineGradientShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = LINE_SHADER_COMMON R"( layout(location = 0) in ivec2 in_pos_normal; layout(location = 1) in uvec4 in_data; @@ -268,7 +275,7 @@ layout(location = 5) in vec2 in_offset; layout(location = 6) in vec2 in_width; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineGradientDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineGradientDrawableUBO { mat4 matrix; mediump float ratio; // Interpolations @@ -281,7 +288,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineGradientDrawableUB float pad2; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; float blur; float opacity; @@ -381,7 +388,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = LINE_SHADER_COMMON R"( layout(location = 0) in lowp vec2 frag_normal; layout(location = 1) in lowp vec2 frag_width2; @@ -400,7 +407,7 @@ layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image0_sam layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; float blur; float opacity; @@ -453,12 +460,11 @@ template <> struct ShaderSource { static constexpr const char* name = "LinePatternShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = LINE_SHADER_COMMON R"( layout(location = 0) in ivec2 in_pos_normal; layout(location = 1) in uvec4 in_data; @@ -491,7 +497,7 @@ layout(location = 7) in uvec4 in_pattern_from; layout(location = 8) in uvec4 in_pattern_to; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LinePatternDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LinePatternDrawableUBO { mat4 matrix; float ratio; // Interpolations @@ -504,7 +510,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LinePatternDrawableUBO float pattern_to_t; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; float blur; float opacity; @@ -621,7 +627,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = LINE_SHADER_COMMON R"( layout(location = 0) in lowp vec2 frag_normal; layout(location = 1) in lowp vec2 frag_width2; @@ -646,7 +652,7 @@ layout(location = 7) in mediump vec4 frag_pattern_to; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LinePatternTilePropertiesUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineTilePropsUBO) uniform LinePatternTilePropertiesUBO { vec4 pattern_from; vec4 pattern_to; vec4 scale; @@ -655,7 +661,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LinePatternTilePropert float pad1; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; float blur; float opacity; @@ -749,12 +755,11 @@ template <> struct ShaderSource { static constexpr const char* name = "LineSDFShader"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = LINE_SHADER_COMMON R"( layout(location = 0) in ivec2 in_pos_normal; layout(location = 1) in uvec4 in_data; @@ -787,7 +792,7 @@ layout(location = 7) in vec2 in_width; layout(location = 8) in vec2 in_floorwidth; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineSDFDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineSDFDrawableUBO { mat4 matrix; vec2 patternscale_a; vec2 patternscale_b; @@ -806,7 +811,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LineSDFDrawableUBO { float pad2; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; float blur; float opacity; @@ -930,7 +935,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = LINE_SHADER_COMMON R"( layout(location = 0) in lowp vec2 frag_normal; layout(location = 1) in lowp vec2 frag_width2; @@ -956,14 +961,14 @@ layout(location = 8) in mediump float frag_floorwidth; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform LineSDFInterpolationUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineTilePropsUBO) uniform LineSDFInterpolationUBO { float sdfgamma; float mix; float pad1; float pad2; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform LineEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; float blur; float opacity; diff --git a/include/mbgl/shaders/vulkan/location_indicator.hpp b/include/mbgl/shaders/vulkan/location_indicator.hpp index f677bb29670..5a06107e559 100644 --- a/include/mbgl/shaders/vulkan/location_indicator.hpp +++ b/include/mbgl/shaders/vulkan/location_indicator.hpp @@ -6,19 +6,25 @@ namespace mbgl { namespace shaders { +#define LOCATION_INDICATOR_SHADER_PRELUDE \ + R"( + +#define idLocationIndicatorDrawableUBO drawableReservedUBOCount + +)" + template <> struct ShaderSource { static constexpr const char* name = "LocationIndicatorShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = LOCATION_INDICATOR_SHADER_PRELUDE R"( layout(location = 0) in vec2 in_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LocationIndicatorDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLocationIndicatorDrawableUBO) uniform LocationIndicatorDrawableUBO { mat4 matrix; vec4 color; } drawable; @@ -29,10 +35,10 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = LOCATION_INDICATOR_SHADER_PRELUDE R"( layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform LocationIndicatorDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLocationIndicatorDrawableUBO) uniform LocationIndicatorDrawableUBO { mat4 matrix; vec4 color; } drawable; @@ -47,7 +53,6 @@ template <> struct ShaderSource { static constexpr const char* name = "LocationIndicatorTexturedShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -56,7 +61,7 @@ struct ShaderSource #include +#define RASTER_SHADER_PRELUDE \ + R"( + +#define idRasterDrawableUBO idDrawableReservedVertexOnlyUBO +#define idRasterEvaluatedPropsUBO layerUBOStartId + +)" + namespace mbgl { namespace shaders { @@ -10,21 +18,20 @@ template <> struct ShaderSource { static constexpr const char* name = "RasterShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = RASTER_SHADER_PRELUDE R"( layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec2 in_texture_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform RasterDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idRasterDrawableUBO) uniform RasterDrawableUBO { mat4 matrix; } drawable; -layout(set = LAYER_SET_INDEX, binding = 0) uniform RasterEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idRasterEvaluatedPropsUBO) uniform RasterEvaluatedPropsUBO { vec4 spin_weights; vec2 tl_parent; float scale_parent; @@ -57,14 +64,14 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = RASTER_SHADER_PRELUDE R"( layout(location = 0) in vec2 frag_position0; layout(location = 1) in vec2 frag_position1; layout(location = 0) out vec4 out_color; -layout(set = LAYER_SET_INDEX, binding = 0) uniform RasterEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idRasterEvaluatedPropsUBO) uniform RasterEvaluatedPropsUBO { vec4 spin_weights; vec2 tl_parent; float scale_parent; diff --git a/include/mbgl/shaders/vulkan/shader_group.hpp b/include/mbgl/shaders/vulkan/shader_group.hpp index 1363ab35e4c..67d56d9bc3a 100644 --- a/include/mbgl/shaders/vulkan/shader_group.hpp +++ b/include/mbgl/shaders/vulkan/shader_group.hpp @@ -77,9 +77,6 @@ class ShaderGroup final : public ShaderGroupBase { for (const auto& attrib : ShaderClass::instanceAttributes) { shader->initInstanceAttribute(attrib); } - for (const auto& uniform : ShaderClass::uniforms) { - shader->initUniformBlock(uniform); - } for (const auto& texture : ShaderClass::textures) { shader->initTexture(texture); } diff --git a/include/mbgl/shaders/vulkan/shader_program.hpp b/include/mbgl/shaders/vulkan/shader_program.hpp index 4cd59471d1a..e4afb9f3083 100644 --- a/include/mbgl/shaders/vulkan/shader_program.hpp +++ b/include/mbgl/shaders/vulkan/shader_program.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -70,13 +69,10 @@ class ShaderProgram final : public gfx::ShaderProgramBase { const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; } const gfx::VertexAttributeArray& getInstanceAttributes() const override { return instanceAttributes; } - const gfx::UniformBlockArray& getUniformBlocks() const override { return uniformBlocks; } - gfx::UniformBlockArray& mutableUniformBlocks() override { return uniformBlocks; } bool hasTextures() const; void initAttribute(const shaders::AttributeInfo&); void initInstanceAttribute(const shaders::AttributeInfo&); - void initUniformBlock(const shaders::UniformBlockInfo&); void initTexture(const shaders::TextureInfo&); protected: @@ -87,7 +83,6 @@ class ShaderProgram final : public gfx::ShaderProgramBase { vk::UniqueShaderModule fragmentShader; std::unordered_map pipelines; - UniformBlockArray uniformBlocks; VertexAttributeArray vertexAttributes; VertexAttributeArray instanceAttributes; std::array, shaders::maxTextureCountPerShader> textureBindings; diff --git a/include/mbgl/shaders/vulkan/symbol.hpp b/include/mbgl/shaders/vulkan/symbol.hpp index 7ede918ea23..c183b500530 100644 --- a/include/mbgl/shaders/vulkan/symbol.hpp +++ b/include/mbgl/shaders/vulkan/symbol.hpp @@ -6,16 +6,24 @@ namespace mbgl { namespace shaders { +#define SYMBOL_SHADER_COMMON \ + R"( + +#define idSymbolDrawableUBO idDrawableReservedVertexOnlyUBO +#define idSymbolTilePropsUBO idDrawableReservedFragmentOnlyUBO +#define idSymbolEvaluatedPropsUBO layerUBOStartId + +)" + template <> struct ShaderSource { static constexpr const char* name = "SymbolIconShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = SYMBOL_SHADER_COMMON R"( layout(location = 0) in ivec4 in_pos_offset; layout(location = 1) in uvec4 in_data; @@ -27,7 +35,7 @@ layout(location = 4) in float in_fade_opacity; layout(location = 5) in vec2 in_opacity; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform SymbolDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; @@ -128,21 +136,21 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = SYMBOL_SHADER_COMMON R"( layout(location = 0) in mediump vec2 frag_tex; layout(location = 1) in mediump float frag_opacity; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolTilePropsUBO) uniform SymbolTilePropsUBO { bool is_text; bool is_halo; float gamma_scale; float pad1; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform SymbolEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idSymbolEvaluatedPropsUBO) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; vec4 text_halo_color; float text_opacity; @@ -180,12 +188,11 @@ template <> struct ShaderSource { static constexpr const char* name = "SymbolSDFIconShader"; - static const std::array uniforms; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = SYMBOL_SHADER_COMMON R"( layout(location = 0) in ivec4 in_pos_offset; layout(location = 1) in uvec4 in_data; @@ -213,7 +220,7 @@ layout(location = 8) in vec2 in_halo_width; layout(location = 9) in vec2 in_halo_blur; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform SymbolDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; @@ -353,7 +360,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = SYMBOL_SHADER_COMMON R"( layout(location = 0) in mediump vec2 frag_tex; layout(location = 1) in mediump float frag_fade_opacity; @@ -382,14 +389,14 @@ layout(location = 8) in mediump float frag_halo_blur; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolTilePropsUBO) uniform SymbolTilePropsUBO { bool is_text; bool is_halo; float gamma_scale; float pad1; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform SymbolEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idSymbolEvaluatedPropsUBO) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; vec4 text_halo_color; float text_opacity; @@ -457,12 +464,11 @@ template <> struct ShaderSource { static constexpr const char* name = "SymbolTextAndIconShader"; - static const std::array uniforms; static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = SYMBOL_SHADER_COMMON R"( #define SDF 1.0 #define ICON 0.0 @@ -492,7 +498,7 @@ layout(location = 7) in vec2 in_halo_width; layout(location = 8) in vec2 in_halo_blur; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform SymbolDrawableUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; @@ -637,7 +643,7 @@ void main() { } )"; - static constexpr auto fragment = R"( + static constexpr auto fragment = SYMBOL_SHADER_COMMON R"( layout(location = 0) in mediump vec2 frag_tex; layout(location = 1) in mediump float frag_fade_opacity; @@ -668,14 +674,14 @@ layout(location = 9) flat in int frag_is_icon; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform SymbolTilePropsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolTilePropsUBO) uniform SymbolTilePropsUBO { bool is_text; bool is_halo; float gamma_scale; float pad1; } tileProps; -layout(set = LAYER_SET_INDEX, binding = 0) uniform SymbolEvaluatedPropsUBO { +layout(set = LAYER_SET_INDEX, binding = idSymbolEvaluatedPropsUBO) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; vec4 text_halo_color; float text_opacity; diff --git a/include/mbgl/shaders/vulkan/widevector.hpp b/include/mbgl/shaders/vulkan/widevector.hpp index 09faf660108..14139f56a3f 100644 --- a/include/mbgl/shaders/vulkan/widevector.hpp +++ b/include/mbgl/shaders/vulkan/widevector.hpp @@ -6,16 +6,23 @@ namespace mbgl { namespace shaders { +#define WIDEVECTOR_SHADER_PRELUDE \ + R"( + +#define idWideVectorUniformsUBO idDrawableReservedVertexOnlyUBO +#define idWideVectorUniformWideVecUBO drawableReservedUBOCount + +)" + template <> struct ShaderSource { static constexpr const char* name = "WideVectorShader"; - static const std::array uniforms; static const std::array attributes; static const std::array instanceAttributes; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = WIDEVECTOR_SHADER_PRELUDE R"( /** Expressions are used to change values like width and opacity over zoom levels. **/ #define WKSExpStops 8 @@ -35,7 +42,7 @@ struct ShaderSource { #define WKSVertexLineCapButt 1 #define WKSVertexLineCapSquare 2 -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform WideVectorUniformsUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idWideVectorUniformsUBO) uniform WideVectorUniformsUBO { mat4 mvpMatrix; mat4 mvpMatrixDiff; mat4 mvMatrix; @@ -45,7 +52,7 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform WideVectorUniformsUBO vec2 frameSize; } uniforms; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 1) uniform WideVectorUniformWideVecUBO { +layout(set = DRAWABLE_UBO_SET_INDEX, binding = idWideVectorUniformWideVecUBO) uniform WideVectorUniformWideVecUBO { vec4 color; float w2; float offset; @@ -149,23 +156,8 @@ void main() { } )"; - static constexpr auto fragment = R"( -layout(location = 0) in vec2 frag_uv; -layout(location = 0) out vec4 out_color; - -layout(set = DRAWABLE_UBO_SET_INDEX, binding = 0) uniform DebugUBO { - mat4 matrix; - vec4 color; - float overlay_scale; - float pad1, pad2, pad3; -} debug; - -layout(set = DRAWABLE_IMAGE_SET_INDEX, binding = 0) uniform sampler2D image_sampler; - -void main() { - vec4 overlay_color = texture(image_sampler, frag_uv); - out_color = mix(debug.color, overlay_color, overlay_color.a); -} + static constexpr auto fragment = WIDEVECTOR_SHADER_PRELUDE R"( + // TODO )"; }; diff --git a/include/mbgl/vulkan/context.hpp b/include/mbgl/vulkan/context.hpp index 08e439df3f6..3208b3d9dc7 100644 --- a/include/mbgl/vulkan/context.hpp +++ b/include/mbgl/vulkan/context.hpp @@ -175,6 +175,7 @@ class Context final : public gfx::Context { void buildImageDescriptorSetLayout(); void buildUniformDescriptorSetLayout(vk::UniqueDescriptorSetLayout& layout, + size_t uniformStartId, size_t uniformCount, const std::string& name); diff --git a/include/mbgl/vulkan/uniform_block.hpp b/include/mbgl/vulkan/uniform_block.hpp deleted file mode 100644 index e32c9ad6001..00000000000 --- a/include/mbgl/vulkan/uniform_block.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include - -namespace mbgl { -namespace vulkan { - -class UniformBlock final : public gfx::UniformBlock { -public: - UniformBlock(int index_, std::size_t size_) - : gfx::UniformBlock(index_, size_) {} - UniformBlock(const UniformBlock& other) - : gfx::UniformBlock(other) {} - UniformBlock(UniformBlock&& other) - : gfx::UniformBlock(std::move(other)) {} - ~UniformBlock() override = default; - - void bindBuffer(const gfx::UniformBuffer&) override {} - void unbindBuffer() override {} - - bool getBindVertex() const { return bindVertex; } - void setBindVertex(bool value) { bindVertex = value; } - - bool getBindFragment() const { return bindFragment; } - void setBindFragment(bool value) { bindFragment = value; } - -protected: - bool bindVertex = false; - bool bindFragment = false; -}; - -/// Stores a collection of uniform blocks by name -class UniformBlockArray final : public gfx::UniformBlockArray { -public: - UniformBlockArray() = default; - UniformBlockArray(UniformBlockArray&& other) - : gfx::UniformBlockArray(std::move(other)) {} - UniformBlockArray(const UniformBlockArray&) = delete; - - UniformBlockArray& operator=(UniformBlockArray&& other) { - gfx::UniformBlockArray::operator=(std::move(other)); - return *this; - } - UniformBlockArray& operator=(const UniformBlockArray& other) { - gfx::UniformBlockArray::operator=(other); - return *this; - } - -private: - std::unique_ptr create(int index, std::size_t size) override { - return std::make_unique(index, size); - } - std::unique_ptr copy(const gfx::UniformBlock& uniformBlocks) override { - return std::make_unique(static_cast(uniformBlocks)); - } -}; - -} // namespace vulkan -} // namespace mbgl diff --git a/include/mbgl/vulkan/uniform_buffer.hpp b/include/mbgl/vulkan/uniform_buffer.hpp index 039ea932b3d..68305401bce 100644 --- a/include/mbgl/vulkan/uniform_buffer.hpp +++ b/include/mbgl/vulkan/uniform_buffer.hpp @@ -51,16 +51,13 @@ class UniformBufferArray final : public gfx::UniformBufferArray { ~UniformBufferArray() = default; const std::shared_ptr& set(const size_t id, - std::shared_ptr uniformBuffer, - bool bindVertex, - bool bindFragment) override; + std::shared_ptr uniformBuffer) override; void createOrUpdate(const size_t id, const void* data, std::size_t size, gfx::Context& context, - bool bindVertex, - bool bindFragment) override; + bool persistent = false) override; void bindDescriptorSets(CommandEncoder& encoder); void freeDescriptorSets() { descriptorSet.reset(); } diff --git a/src/mbgl/gfx/uniform_block.cpp b/src/mbgl/gfx/uniform_block.cpp deleted file mode 100644 index 77a892193f6..00000000000 --- a/src/mbgl/gfx/uniform_block.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#include - -namespace mbgl { -namespace gfx { - -std::unique_ptr UniformBlockArray::nullref = nullptr; - -UniformBlockArray::UniformBlockArray(UniformBlockArray&& other) - : uniformBlockVector(std::move(other.uniformBlockVector)) {} - -UniformBlockArray& UniformBlockArray::operator=(UniformBlockArray&& other) { - uniformBlockVector = std::move(other.uniformBlockVector); - return *this; -} - -UniformBlockArray& UniformBlockArray::operator=(const UniformBlockArray& other) { - for (size_t id = 0; id < other.uniformBlockVector.size(); id++) { - uniformBlockVector[id] = copy(*other.uniformBlockVector[id]); - } - return *this; -} - -const std::unique_ptr& UniformBlockArray::get(const size_t id) const { - return (id < uniformBlockVector.size()) ? uniformBlockVector[id] : nullref; -} - -const std::unique_ptr& UniformBlockArray::set(const size_t id, const size_t index, std::size_t size) { - assert(id < uniformBlockVector.size()); - if (id >= uniformBlockVector.size()) { - return nullref; - } - uniformBlockVector[id] = create(static_cast(index), size); - return uniformBlockVector[id]; -} - -} // namespace gfx -} // namespace mbgl diff --git a/src/mbgl/gfx/uniform_buffer.cpp b/src/mbgl/gfx/uniform_buffer.cpp index b1ba94cff71..bf4edd7f6d6 100644 --- a/src/mbgl/gfx/uniform_buffer.cpp +++ b/src/mbgl/gfx/uniform_buffer.cpp @@ -27,38 +27,29 @@ const std::shared_ptr& UniformBufferArray::get(const size_t id) c } const std::shared_ptr& UniformBufferArray::set(const size_t id, - std::shared_ptr uniformBuffer, - bool bindVertex, - bool bindFragment) { + std::shared_ptr uniformBuffer) { assert(id < uniformBufferVector.size()); if (id >= uniformBufferVector.size()) { return nullref; } uniformBufferVector[id] = std::move(uniformBuffer); - if (uniformBufferVector[id]) { - uniformBufferVector[id]->setBindVertex(bindVertex); - uniformBufferVector[id]->setBindFragment(bindFragment); - } return uniformBufferVector[id]; } void UniformBufferArray::createOrUpdate( - const size_t id, const std::vector& data, gfx::Context& context, bool bindVertex, bool bindFragment) { - createOrUpdate(id, data.data(), data.size(), context, bindVertex, bindFragment); + const size_t id, const std::vector& data, gfx::Context& context, bool persistent) { + createOrUpdate(id, data.data(), data.size(), context, persistent); } void UniformBufferArray::createOrUpdate(const size_t id, const void* data, const std::size_t size, gfx::Context& context, - bool bindVertex, - bool bindFragment) { + bool persistent) { if (auto& ubo = get(id); ubo && ubo->getSize() == size) { ubo->update(data, size); } else { - uniformBufferVector[id] = context.createUniformBuffer(data, size, false); - uniformBufferVector[id]->setBindVertex(bindVertex); - uniformBufferVector[id]->setBindFragment(bindFragment); + uniformBufferVector[id] = context.createUniformBuffer(data, size, persistent); } } diff --git a/src/mbgl/gl/uniform_block_gl.cpp b/src/mbgl/gl/uniform_block_gl.cpp deleted file mode 100644 index c53a9cd8673..00000000000 --- a/src/mbgl/gl/uniform_block_gl.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -namespace mbgl { -namespace gl { - -using namespace platform; - -void UniformBlockGL::bindBuffer(const gfx::UniformBuffer& uniformBuffer) { - assert(size == uniformBuffer.getSize()); - GLint binding = index; - const auto& uniformBufferGL = static_cast(uniformBuffer); - MBGL_CHECK_ERROR(glBindBufferRange(GL_UNIFORM_BUFFER, - binding, - uniformBufferGL.getID(), - uniformBufferGL.getManagedBuffer().getBindingOffset(), - uniformBufferGL.getSize())); -} - -void UniformBlockGL::unbindBuffer() { - GLint binding = index; - MBGL_CHECK_ERROR(glBindBufferBase(GL_UNIFORM_BUFFER, binding, 0)); -} - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/mtl/context.cpp b/src/mbgl/mtl/context.cpp index 0842ea50f56..675d5c8d120 100644 --- a/src/mbgl/mtl/context.cpp +++ b/src/mbgl/mtl/context.cpp @@ -57,7 +57,7 @@ Context::~Context() noexcept { stencilStateRenderable = nullptr; for (size_t i = 0; i < globalUniformBuffers.allocatedSize(); i++) { - globalUniformBuffers.set(i, nullptr, false, false); + globalUniformBuffers.set(i, nullptr); } #if !defined(NDEBUG) diff --git a/src/mbgl/mtl/drawable.cpp b/src/mbgl/mtl/drawable.cpp index 3746f039b13..27ca784a525 100644 --- a/src/mbgl/mtl/drawable.cpp +++ b/src/mbgl/mtl/drawable.cpp @@ -521,7 +521,6 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) { return; } const auto& shaderMTL = static_cast(*shader); - const auto& shaderUniforms = shaderMTL.getUniformBlocks(); auto& uploadPass = static_cast(uploadPass_); auto& contextBase = uploadPass.getContext(); diff --git a/src/mbgl/mtl/uniform_block.cpp b/src/mbgl/mtl/uniform_block.cpp deleted file mode 100644 index e2b436a5c8c..00000000000 --- a/src/mbgl/mtl/uniform_block.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -#include - -#include - -namespace mbgl { -namespace mtl { - -void UniformBlock::bindBuffer(const gfx::UniformBuffer& uniformBuffer) { - assert(size == uniformBuffer.getSize()); -} - -void UniformBlock::unbindBuffer() {} - -} // namespace mtl -} // namespace mbgl diff --git a/src/mbgl/mtl/uniform_buffer.cpp b/src/mbgl/mtl/uniform_buffer.cpp index 1b346f33823..4349af8a93b 100644 --- a/src/mbgl/mtl/uniform_buffer.cpp +++ b/src/mbgl/mtl/uniform_buffer.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -44,10 +45,10 @@ void UniformBufferArray::bind(RenderPass& renderPass) const noexcept { if (!uniformBuffer) continue; const auto& buffer = static_cast(*uniformBuffer.get()); const auto& resource = buffer.getBufferResource(); - if (buffer.getBindVertex()) { + if (id != shaders::idDrawableReservedFragmentOnlyUBO) { renderPass.bindVertex(resource, 0, id); } - if (buffer.getBindFragment()) { + if (id != shaders::idDrawableReservedVertexOnlyUBO) { renderPass.bindFragment(resource, 0, id); } } diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index a513c65086d..769a5818eb7 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -63,14 +63,14 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara /* .scale_b = */ crossfade.toScale, /* .mix = */ crossfade.t, /* .opacity = */ evaluated.get()}; - layerUniforms.createOrUpdate(idBackgroundPropsUBO, &propsUBO, context, true, true); + layerUniforms.createOrUpdate(idBackgroundPropsUBO, &propsUBO, context); } else { const BackgroundPropsUBO propsUBO = {/* .color = */ evaluated.get(), /* .opacity = */ evaluated.get(), /* .pad1 = */ 0, /* .pad2 = */ 0, /* .pad3 = */ 0}; - layerUniforms.createOrUpdate(idBackgroundPropsUBO, &propsUBO, context, false, true); + layerUniforms.createOrUpdate(idBackgroundPropsUBO, &propsUBO, context); } #if MLN_UBO_CONSOLIDATION @@ -122,7 +122,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara /* .pad3 = */ 0 }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); #endif } else { @@ -134,7 +134,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara /* .matrix = */ util::cast(matrix) }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idBackgroundDrawableUBO, &drawableUBO, context); #endif } @@ -151,7 +151,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } - layerUniforms.set(idBackgroundDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idBackgroundDrawableUBO, drawableUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index d8cb610acd6..1a2f461a810 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -56,7 +56,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); + layerUniforms.set(idCircleEvaluatedPropsUBO, evaluatedPropsUniformBuffer); #if MLN_UBO_CONSOLIDATION int i = 0; @@ -111,7 +111,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete drawable.setUBOIndex(i++); #else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context); #endif }); @@ -123,7 +123,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } - layerUniforms.set(idCircleDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idCircleDrawableUBO, drawableUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp index fd50d4723de..76f653d1e70 100644 --- a/src/mbgl/renderer/layers/collision_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/collision_layer_tweaker.cpp @@ -66,8 +66,8 @@ void CollisionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam /* .pad1 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idCollisionDrawableUBO, &drawableUBO, context, true, false); - drawableUniforms.createOrUpdate(idCollisionTilePropsUBO, &tilePropsUBO, context, true, true); + drawableUniforms.createOrUpdate(idCollisionDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idCollisionTilePropsUBO, &tilePropsUBO, context); }); } diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index 0d4aba89913..cf4d8374f1b 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -56,7 +56,7 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP /* .to_scale = */ crossfade.toScale, /* .pad2 = */ 0}; auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idFillExtrusionPropsUBO, &propsUBO, context, true, true); + layerUniforms.createOrUpdate(idFillExtrusionPropsUBO, &propsUBO, context); propertiesUpdated = false; @@ -147,8 +147,8 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP drawable.setUBOIndex(i++); #else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context, true, false); - drawableUniforms.createOrUpdate(idFillExtrusionTilePropsUBO, &tilePropsUBO, context, true, true); + drawableUniforms.createOrUpdate(idFillExtrusionDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idFillExtrusionTilePropsUBO, &tilePropsUBO, context); #endif }); @@ -167,8 +167,8 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } - layerUniforms.set(idFillExtrusionDrawableUBO, drawableUniformBuffer, true, false); - layerUniforms.set(idFillExtrusionTilePropsUBO, tilePropsUniformBuffer, true, true); + layerUniforms.set(idFillExtrusionDrawableUBO, drawableUniformBuffer); + layerUniforms.set(idFillExtrusionTilePropsUBO, tilePropsUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 5d070465e9b..5060fd91bc5 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -50,7 +50,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idFillEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); + layerUniforms.set(idFillEvaluatedPropsUBO, evaluatedPropsUniformBuffer); const auto& translation = evaluated.get(); const auto anchor = evaluated.get(); @@ -119,7 +119,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); #endif break; } @@ -138,7 +138,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); #endif break; } @@ -175,8 +175,8 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); - drawableUniforms.createOrUpdate(idFillTilePropsUBO, &tilePropsUBO, context, true, true); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idFillTilePropsUBO, &tilePropsUBO, context); #endif break; } @@ -213,8 +213,8 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); - drawableUniforms.createOrUpdate(idFillTilePropsUBO, &tilePropsUBO, context, true, true); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idFillTilePropsUBO, &tilePropsUBO, context); #endif break; } @@ -232,7 +232,7 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, context); #endif break; } @@ -263,8 +263,8 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } - layerUniforms.set(idFillDrawableUBO, drawableUniformBuffer, true, false); - layerUniforms.set(idFillTilePropsUBO, tilePropsUniformBuffer, true, true); + layerUniforms.set(idFillDrawableUBO, drawableUniformBuffer); + layerUniforms.set(idFillTilePropsUBO, tilePropsUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index 4f4c2ffc917..7cbff4afabe 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -44,7 +44,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idHeatmapEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); + layerUniforms.set(idHeatmapEvaluatedPropsUBO, evaluatedPropsUniformBuffer); #if MLN_UBO_CONSOLIDATION int i = 0; @@ -86,7 +86,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet drawable.setUBOIndex(i++); #else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idHeatmapDrawableUBO, &drawableUBO, context); #endif }); @@ -98,7 +98,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } - layerUniforms.set(idSymbolDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idSymbolDrawableUBO, drawableUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index 61254467d85..165958c16f6 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -39,7 +39,7 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint /* .pad2 = */ 0, /* .pad3 = */ 0}; auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idHeatmapTexturePropsUBO, &propsUBO, parameters.context, true, true); + layerUniforms.createOrUpdate(idHeatmapTexturePropsUBO, &propsUBO, parameters.context); } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index abf9fab6136..ac486d9a00a 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -52,7 +52,7 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idHillshadeEvaluatedPropsUBO, evaluatedPropsUniformBuffer, false, true); + layerUniforms.set(idHillshadeEvaluatedPropsUBO, evaluatedPropsUniformBuffer); #if MLN_UBO_CONSOLIDATION int i = 0; @@ -91,8 +91,8 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam drawable.setUBOIndex(i++); #else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idHillshadeDrawableUBO, &drawableUBO, parameters.context, true, false); - drawableUniforms.createOrUpdate(idHillshadeTilePropsUBO, &tilePropsUBO, parameters.context, false, true); + drawableUniforms.createOrUpdate(idHillshadeDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idHillshadeTilePropsUBO, &tilePropsUBO, parameters.context); #endif }); @@ -112,8 +112,8 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } - layerUniforms.set(idHillshadeDrawableUBO, drawableUniformBuffer, true, false); - layerUniforms.set(idHillshadeTilePropsUBO, tilePropsUniformBuffer, false, true); + layerUniforms.set(idHillshadeDrawableUBO, drawableUniformBuffer); + layerUniforms.set(idHillshadeTilePropsUBO, tilePropsUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp index 4b4d5be43b1..3a9e337d140 100644 --- a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp @@ -58,8 +58,8 @@ void HillshadePrepareLayerTweaker::execute(LayerGroupBase& layerGroup, const Pai /* .maxzoom = */ static_cast(drawableData.maxzoom)}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idHillshadePrepareDrawableUBO, &drawableUBO, parameters.context, true, false); - drawableUniforms.createOrUpdate(idHillshadePrepareTilePropsUBO, &tilePropsUBO, parameters.context, true, true); + drawableUniforms.createOrUpdate(idHillshadePrepareDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idHillshadePrepareTilePropsUBO, &tilePropsUBO, parameters.context); }); } diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index f76fca573df..87b7b432487 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -148,11 +148,11 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idLineEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); + layerUniforms.set(idLineEvaluatedPropsUBO, evaluatedPropsUniformBuffer); #if MLN_RENDER_BACKEND_METAL // GPU Expressions - layerUniforms.set(idLineExpressionUBO, getExpressionBuffer(), true, true); + layerUniforms.set(idLineExpressionUBO, getExpressionBuffer()); #endif // MLN_RENDER_BACKEND_METAL #if MLN_UBO_CONSOLIDATION @@ -208,7 +208,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); #endif } break; @@ -232,7 +232,7 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); #endif } break; @@ -279,8 +279,8 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); - drawableUniforms.createOrUpdate(idLineTilePropsUBO, &tilePropsUBO, context, false, true); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idLineTilePropsUBO, &tilePropsUBO, context); #endif } break; @@ -342,8 +342,8 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters }; #if !MLN_UBO_CONSOLIDATION - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context, true, false); - drawableUniforms.createOrUpdate(idLineTilePropsUBO, &tilePropsUBO, context, false, true); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idLineTilePropsUBO, &tilePropsUBO, context); #endif } } break; @@ -374,8 +374,8 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } - layerUniforms.set(idLineDrawableUBO, drawableUniformBuffer, true, false); - layerUniforms.set(idLineTilePropsUBO, tilePropsUniformBuffer, false, true); + layerUniforms.set(idLineDrawableUBO, drawableUniformBuffer); + layerUniforms.set(idLineTilePropsUBO, tilePropsUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp b/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp index 3c60a19e35d..8d60a3a4517 100644 --- a/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/location_indicator_layer_tweaker.cpp @@ -29,8 +29,7 @@ void LocationIndicatorLayerTweaker::execute(LayerGroupBase& layerGroup, const Pa case RenderLocationIndicatorLayer::LocationIndicatorComponentType::Circle: { LocationIndicatorDrawableUBO drawableUBO = {/* .matrix = */ util::cast(projectionCircle), /* .color = */ props.evaluated.get()}; - drawableUniforms.createOrUpdate( - idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); + drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context); break; } @@ -38,8 +37,7 @@ void LocationIndicatorLayerTweaker::execute(LayerGroupBase& layerGroup, const Pa LocationIndicatorDrawableUBO drawableUBO = { /* .matrix = */ util::cast(projectionCircle), /* .color = */ props.evaluated.get()}; - drawableUniforms.createOrUpdate( - idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); + drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context); break; } @@ -50,8 +48,7 @@ void LocationIndicatorLayerTweaker::execute(LayerGroupBase& layerGroup, const Pa case RenderLocationIndicatorLayer::LocationIndicatorComponentType::PuckHat: { const LocationIndicatorDrawableUBO drawableUBO = {/* .matrix = */ util::cast(projectionPuck), /* .color = */ Color::black()}; - drawableUniforms.createOrUpdate( - idLocationIndicatorDrawableUBO, &drawableUBO, params.context, true, true); + drawableUniforms.createOrUpdate(idLocationIndicatorDrawableUBO, &drawableUBO, params.context); break; } diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index 442da2c7583..6b7fb5b1ea1 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -63,7 +63,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idRasterEvaluatedPropsUBO, evaluatedPropsUniformBuffer, true, true); + layerUniforms.set(idRasterEvaluatedPropsUBO, evaluatedPropsUniformBuffer); #if MLN_UBO_CONSOLIDATION int i = 0; @@ -111,7 +111,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, drawable.setUBOIndex(i++); #else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idRasterDrawableUBO, &drawableUBO, parameters.context, true, false); + drawableUniforms.createOrUpdate(idRasterDrawableUBO, &drawableUBO, parameters.context); #endif }); @@ -124,7 +124,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } - layerUniforms.set(idRasterDrawableUBO, drawableUniformBuffer, true, false); + layerUniforms.set(idRasterDrawableUBO, drawableUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index 65a3d4ea014..4455fc9626d 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -86,7 +86,7 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete propertiesUpdated = false; } auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.set(idSymbolEvaluatedPropsUBO, evaluatedPropsUniformBuffer, false, true); + layerUniforms.set(idSymbolEvaluatedPropsUBO, evaluatedPropsUniformBuffer); #if MLN_UBO_CONSOLIDATION int i = 0; @@ -195,8 +195,8 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete drawable.setUBOIndex(i++); #else auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idSymbolDrawableUBO, &drawableUBO, context, true, false); - drawableUniforms.createOrUpdate(idSymbolTilePropsUBO, &tilePropsUBO, context, false, true); + drawableUniforms.createOrUpdate(idSymbolDrawableUBO, &drawableUBO, context); + drawableUniforms.createOrUpdate(idSymbolTilePropsUBO, &tilePropsUBO, context); #endif }); @@ -215,8 +215,8 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } - layerUniforms.set(idSymbolDrawableUBO, drawableUniformBuffer, true, false); - layerUniforms.set(idSymbolTilePropsUBO, tilePropsUniformBuffer, false, true); + layerUniforms.set(idSymbolDrawableUBO, drawableUniformBuffer); + layerUniforms.set(idSymbolTilePropsUBO, tilePropsUniformBuffer); #endif } diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 941f3185e85..ff10be6dd62 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -287,7 +287,7 @@ void Renderer::Impl::render(const RenderTree& renderTree, /* .pad1 = */ 0, }; auto& globalUniforms = context.mutableGlobalUniformBuffers(); - globalUniforms.createOrUpdate(shaders::idGlobalPaintParamsUBO, &globalPaintParamsUBO, context, true, true); + globalUniforms.createOrUpdate(shaders::idGlobalPaintParamsUBO, &globalPaintParamsUBO, context); #endif // - 3D PASS diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index b32f19dc452..82a48a63d92 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -92,7 +92,7 @@ class PolylineLayerTweaker : public LayerTweaker { void execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) override { auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); + layerUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); @@ -106,7 +106,7 @@ class PolylineLayerTweaker : public LayerTweaker { /* .width = */ nullptr, /* .floorWidth = */ nullptr, }; - layerUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context, true, true); + layerUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context); } private: @@ -216,7 +216,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr auto updatedCount = tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) { // update existing drawable auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context, true, true); + drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context); }); return updatedCount; }; @@ -245,7 +245,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr for (auto& drawable : debugBuilder->clearDrawables()) { drawable->setTileID(tileID); auto& drawableUniforms = drawable->mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context, true, true); + drawableUniforms.createOrUpdate(idDebugUBO, &debugUBO, context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); } @@ -297,11 +297,10 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr /* .width_t = */ 0.f, /* .pad1 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context, true, false); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); #if !MLN_RENDER_BACKEND_VULKAN - drawableUniforms.createOrUpdate( - idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); + drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); @@ -315,7 +314,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr /* .width = */ nullptr, /* .floorWidth = */ nullptr, }; - drawableUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context, true, true); + drawableUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context); #endif }; diff --git a/src/mbgl/shaders/gl/shader_info.cpp b/src/mbgl/shaders/gl/shader_info.cpp index c7c80ec58c3..e017a8ce117 100644 --- a/src/mbgl/shaders/gl/shader_info.cpp +++ b/src/mbgl/shaders/gl/shader_info.cpp @@ -18,37 +18,41 @@ TextureInfo::TextureInfo(std::string_view name_, std::size_t id_) id(id_) {} // Background -const std::vector ShaderInfo::uniformBlocks = { +using BackgroundShaderInfo= ShaderInfo; + +const std::vector BackgroundShaderInfo::uniformBlocks = { UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, UniformBlockInfo{"BackgroundPropsUBO", idBackgroundPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector BackgroundShaderInfo::attributes = { AttributeInfo{"a_pos", idBackgroundPosVertexAttribute}, }; -const std::vector ShaderInfo::textures = {}; +const std::vector BackgroundShaderInfo::textures = {}; // Background Pattern -const std::vector - ShaderInfo::uniformBlocks = { +using BackgroundPatternShaderInfo = ShaderInfo; + +const std::vector BackgroundPatternShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"BackgroundPatternDrawableUBO", idBackgroundDrawableUBO}, UniformBlockInfo{"BackgroundPatternPropsUBO", idBackgroundPropsUBO}, }; -const std::vector ShaderInfo::attributes = - { +const std::vector BackgroundPatternShaderInfo::attributes = { AttributeInfo{"a_pos", idBackgroundPosVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector BackgroundPatternShaderInfo::textures = { TextureInfo{"u_image", idBackgroundImageTexture}, }; // Circle -const std::vector ShaderInfo::uniformBlocks = { +using CircleShaderInfo = ShaderInfo; + +const std::vector CircleShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"CircleDrawableUBO", idCircleDrawableUBO}, UniformBlockInfo{"CircleEvaluatedPropsUBO", idCircleEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector CircleShaderInfo::attributes = { AttributeInfo{"a_pos", idCirclePosVertexAttribute}, AttributeInfo{"a_color", idCircleColorVertexAttribute}, AttributeInfo{"a_radius", idCircleRadiusVertexAttribute}, @@ -58,165 +62,174 @@ const std::vector ShaderInfo ShaderInfo::textures = {}; +const std::vector CircleShaderInfo::textures = {}; // Collision Box -const std::vector ShaderInfo::uniformBlocks = - { +using CollisionBoxShaderInfo = ShaderInfo; + +const std::vector CollisionBoxShaderInfo::uniformBlocks = { UniformBlockInfo{"CollisionDrawableUBO", idCollisionDrawableUBO}, UniformBlockInfo{"CollisionTilePropsUBO", idCollisionTilePropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector CollisionBoxShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, AttributeInfo{"a_anchor_pos", idCollisionAnchorPosVertexAttribute}, AttributeInfo{"a_extrude", idCollisionExtrudeVertexAttribute}, AttributeInfo{"a_placed", idCollisionPlacedVertexAttribute}, AttributeInfo{"a_shift", idCollisionShiftVertexAttribute}, }; -const std::vector ShaderInfo::textures = {}; +const std::vector CollisionBoxShaderInfo::textures = {}; // Collision Circle -const std::vector - ShaderInfo::uniformBlocks = { +using CollisionCircleShaderInfo = ShaderInfo; + +const std::vector CollisionCircleShaderInfo::uniformBlocks = { UniformBlockInfo{"CollisionDrawableUBO", idCollisionDrawableUBO}, UniformBlockInfo{"CollisionTilePropsUBO", idCollisionTilePropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector CollisionCircleShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, AttributeInfo{"a_anchor_pos", idCollisionAnchorPosVertexAttribute}, AttributeInfo{"a_extrude", idCollisionExtrudeVertexAttribute}, AttributeInfo{"a_placed", idCollisionPlacedVertexAttribute}, }; -const std::vector ShaderInfo::textures = {}; +const std::vector CollisionCircleShaderInfo::textures = {}; // Custom Symbol Icon -const std::vector - ShaderInfo::uniformBlocks = { +using CustomSymbolIconShaderInfo = ShaderInfo; + +const std::vector CustomSymbolIconShaderInfo::uniformBlocks = { UniformBlockInfo{"CustomSymbolIconDrawableUBO", idCustomSymbolDrawableUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector CustomSymbolIconShaderInfo::attributes = { AttributeInfo{"a_pos", idCustomSymbolPosVertexAttribute}, AttributeInfo{"a_tex", idCustomSymbolTexVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector CustomSymbolIconShaderInfo::textures = { TextureInfo{"u_texture", idCustomSymbolImageTexture}, }; // Debug -const std::vector ShaderInfo::uniformBlocks = { +using DebugShaderInfo = ShaderInfo; + +const std::vector DebugShaderInfo::uniformBlocks = { UniformBlockInfo{"DebugUBO", idDebugUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector DebugShaderInfo::attributes = { AttributeInfo{"a_pos", idDebugPosVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector DebugShaderInfo::textures = { TextureInfo{"u_overlay", idDebugOverlayTexture}, }; // Fill -const std::vector ShaderInfo::uniformBlocks = { +using FillShaderInfo = ShaderInfo; + +const std::vector FillShaderInfo::uniformBlocks = { UniformBlockInfo{"FillDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector FillShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, AttributeInfo{"a_color", idFillColorVertexAttribute}, AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, }; -const std::vector ShaderInfo::textures = {}; +const std::vector FillShaderInfo::textures = {}; // Fill Outline -const std::vector ShaderInfo::uniformBlocks = - { +using FillOutlineShaderInfo = ShaderInfo; + +const std::vector FillOutlineShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillOutlineDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector FillOutlineShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, AttributeInfo{"a_outline_color", idFillOutlineColorVertexAttribute}, AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, }; -const std::vector ShaderInfo::textures = {}; +const std::vector FillOutlineShaderInfo::textures = {}; // Fill Pattern -const std::vector ShaderInfo::uniformBlocks = - { +using FillPatternShaderInfo = ShaderInfo; + +const std::vector FillPatternShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillPatternDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillPatternTilePropsUBO", idFillTilePropsUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector FillPatternShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, AttributeInfo{"a_pattern_from", idFillPatternFromVertexAttribute}, AttributeInfo{"a_pattern_to", idFillPatternToVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector FillPatternShaderInfo::textures = { TextureInfo{"u_image", idFillImageTexture}, }; // Fill Outline Pattern -const std::vector - ShaderInfo::uniformBlocks = { +using FillOutlinePatternShaderInfo = ShaderInfo; + +const std::vector FillOutlinePatternShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillOutlinePatternTilePropsUBO", idFillTilePropsUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = - { +const std::vector FillOutlinePatternShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, AttributeInfo{"a_pattern_from", idFillPatternFromVertexAttribute}, AttributeInfo{"a_pattern_to", idFillPatternToVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector FillOutlinePatternShaderInfo::textures = { TextureInfo{"u_image", idFillImageTexture}, }; // Fill Outline Triangulated -const std::vector - ShaderInfo::uniformBlocks = { +using FillOutlineTriangulatedShaderInfo = ShaderInfo; + +const std::vector FillOutlineTriangulatedShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillOutlineTriangulatedDrawableUBO", idFillDrawableUBO}, UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; -const std::vector - ShaderInfo::attributes = { +const std::vector FillOutlineTriangulatedShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, }; -const std::vector - ShaderInfo::textures = {}; +const std::vector FillOutlineTriangulatedShaderInfo::textures = {}; // Fill Extrusion -const std::vector - ShaderInfo::uniformBlocks = { +using FillExtrusionShaderInfo = ShaderInfo; + +const std::vector FillExtrusionShaderInfo::uniformBlocks = { UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector FillExtrusionShaderInfo::attributes = { AttributeInfo{"a_pos", idFillExtrusionPosVertexAttribute}, AttributeInfo{"a_normal_ed", idFillExtrusionNormalEdVertexAttribute}, AttributeInfo{"a_base", idFillExtrusionBaseVertexAttribute}, AttributeInfo{"a_height", idFillExtrusionHeightVertexAttribute}, AttributeInfo{"a_color", idFillExtrusionColorVertexAttribute}, }; -const std::vector ShaderInfo::textures = {}; +const std::vector FillExtrusionShaderInfo::textures = {}; // Fill Extrusion Pattern -const std::vector - ShaderInfo::uniformBlocks = { +using FillExtrusionPatternShaderInfo = ShaderInfo; + +const std::vector FillExtrusionPatternShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, }; -const std::vector - ShaderInfo::attributes = { +const std::vector FillExtrusionPatternShaderInfo::attributes = { AttributeInfo{"a_pos", idFillExtrusionPosVertexAttribute}, AttributeInfo{"a_normal_ed", idFillExtrusionNormalEdVertexAttribute}, AttributeInfo{"a_base", idFillExtrusionBaseVertexAttribute}, @@ -224,71 +237,79 @@ const std::vector AttributeInfo{"a_pattern_from", idFillExtrusionPatternFromVertexAttribute}, AttributeInfo{"a_pattern_to", idFillExtrusionPatternToVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector FillExtrusionPatternShaderInfo::textures = { TextureInfo{"u_image", idFillExtrusionImageTexture}, }; // Heatmap -const std::vector ShaderInfo::uniformBlocks = { +using HeatmapShaderInfo = ShaderInfo; + +const std::vector HeatmapShaderInfo::uniformBlocks = { UniformBlockInfo{"HeatmapDrawableUBO", idHeatmapDrawableUBO}, UniformBlockInfo{"HeatmapEvaluatedPropsUBO", idHeatmapEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector HeatmapShaderInfo::attributes = { AttributeInfo{"a_pos", idHeatmapPosVertexAttribute}, AttributeInfo{"a_weight", idHeatmapWeightVertexAttribute}, AttributeInfo{"a_radius", idHeatmapRadiusVertexAttribute}, }; -const std::vector ShaderInfo::textures = {}; +const std::vector HeatmapShaderInfo::textures = {}; // Heatmap Texture -const std::vector - ShaderInfo::uniformBlocks = { +using HeatmapTextureShaderInfo = ShaderInfo; + +const std::vector HeatmapTextureShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"HeatmapTexturePropsUBO", idHeatmapTexturePropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector HeatmapTextureShaderInfo::attributes = { AttributeInfo{"a_pos", idHeatmapPosVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector HeatmapTextureShaderInfo::textures = { TextureInfo{"u_image", idHeatmapImageTexture}, TextureInfo{"u_color_ramp", idHeatmapColorRampTexture}, }; // Hillshade Prepare -const std::vector - ShaderInfo::uniformBlocks = { +using HillshadePrepareShaderInfo = ShaderInfo; + +const std::vector HillshadePrepareShaderInfo::uniformBlocks = { UniformBlockInfo{"HillshadePrepareDrawableUBO", idHillshadePrepareDrawableUBO}, UniformBlockInfo{"HillshadePrepareTilePropsUBO", idHillshadePrepareTilePropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector HillshadePrepareShaderInfo::attributes = { AttributeInfo{"a_pos", idHillshadePosVertexAttribute}, AttributeInfo{"a_texture_pos", idHillshadeTexturePosVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector HillshadePrepareShaderInfo::textures = { TextureInfo{"u_image", idHillshadeImageTexture}, }; // Hillshade -const std::vector ShaderInfo::uniformBlocks = { +using HillshadeShaderInfo = ShaderInfo; + +const std::vector HillshadeShaderInfo::uniformBlocks = { UniformBlockInfo{"HillshadeDrawableUBO", idHillshadeDrawableUBO}, UniformBlockInfo{"HillshadeTilePropsUBO", idHillshadeTilePropsUBO}, UniformBlockInfo{"HillshadeEvaluatedPropsUBO", idHillshadeEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector HillshadeShaderInfo::attributes = { AttributeInfo{"a_pos", idHillshadePosVertexAttribute}, AttributeInfo{"a_texture_pos", idHillshadeTexturePosVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector HillshadeShaderInfo::textures = { TextureInfo{"u_image", idHillshadeImageTexture}, }; // Line -const std::vector ShaderInfo::uniformBlocks = { +using LineShaderInfo = ShaderInfo; + +const std::vector LineShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LineDrawableUBO", idLineDrawableUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector LineShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, AttributeInfo{"a_color", idLineColorVertexAttribute}, @@ -298,16 +319,17 @@ const std::vector ShaderInfo ShaderInfo::textures = {}; +const std::vector LineShaderInfo::textures = {}; // Line Gradient -const std::vector ShaderInfo::uniformBlocks = - { +using LineGradientShaderInfo = ShaderInfo; + +const std::vector LineGradientShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LineGradientDrawableUBO", idLineDrawableUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector LineGradientShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, AttributeInfo{"a_blur", idLineBlurVertexAttribute}, @@ -316,19 +338,20 @@ const std::vector ShaderInfo ShaderInfo::textures = { +const std::vector LineGradientShaderInfo::textures = { TextureInfo{"u_image", idLineImageTexture}, }; // Line Pattern -const std::vector ShaderInfo::uniformBlocks = - { +using LinePatternShaderInfo = ShaderInfo; + +const std::vector LinePatternShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LinePatternDrawableUBO", idLineDrawableUBO}, UniformBlockInfo{"LinePatternTilePropsUBO", idLineTilePropsUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector LinePatternShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, AttributeInfo{"a_blur", idLineBlurVertexAttribute}, @@ -339,18 +362,20 @@ const std::vector ShaderInfo ShaderInfo::textures = { +const std::vector LinePatternShaderInfo::textures = { TextureInfo{"u_image", idLineImageTexture}, }; // Line SDF -const std::vector ShaderInfo::uniformBlocks = { +using LineSDFShaderInfo = ShaderInfo; + +const std::vector LineSDFShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"LineSDFDrawableUBO", idLineDrawableUBO}, UniformBlockInfo{"LineSDFTilePropsUBO", idLineTilePropsUBO}, UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector LineSDFShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, AttributeInfo{"a_data", idLineDataVertexAttribute}, AttributeInfo{"a_color", idLineColorVertexAttribute}, @@ -361,32 +386,36 @@ const std::vector ShaderInfo ShaderInfo::textures = { +const std::vector LineSDFShaderInfo::textures = { TextureInfo{"u_image", idLineImageTexture}, }; // Raster -const std::vector ShaderInfo::uniformBlocks = { +using RasterShaderInfo = ShaderInfo; + +const std::vector RasterShaderInfo::uniformBlocks = { UniformBlockInfo{"RasterDrawableUBO", idRasterDrawableUBO}, UniformBlockInfo{"RasterEvaluatedPropsUBO", idRasterEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector RasterShaderInfo::attributes = { AttributeInfo{"a_pos", idRasterPosVertexAttribute}, AttributeInfo{"a_texture_pos", idRasterTexturePosVertexAttribute}, }; -const std::vector ShaderInfo::textures = { +const std::vector RasterShaderInfo::textures = { TextureInfo{"u_image0", idRasterImage0Texture}, TextureInfo{"u_image1", idRasterImage0Texture}, }; // Symbol Icon -const std::vector ShaderInfo::uniformBlocks = { +using SymbolIconShaderInfo = ShaderInfo; + +const std::vector SymbolIconShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector SymbolIconShaderInfo::attributes = { AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, AttributeInfo{"a_data", idSymbolDataVertexAttribute}, AttributeInfo{"a_pixeloffset", idSymbolPixelOffsetVertexAttribute}, @@ -394,19 +423,20 @@ const std::vector ShaderInfo ShaderInfo::textures = { +const std::vector SymbolIconShaderInfo::textures = { TextureInfo{"u_texture", idSymbolImageTexture}, }; // Symbol SDF -const std::vector - ShaderInfo::uniformBlocks = { +using SymbolSDFIconShaderInfo = ShaderInfo; + +const std::vector SymbolSDFIconShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = { +const std::vector SymbolSDFIconShaderInfo::attributes = { AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, AttributeInfo{"a_data", idSymbolDataVertexAttribute}, AttributeInfo{"a_pixeloffset", idSymbolPixelOffsetVertexAttribute}, @@ -418,20 +448,20 @@ const std::vector ShaderInfo ShaderInfo::textures = { +const std::vector SymbolSDFIconShaderInfo::textures = { TextureInfo{"u_texture", idSymbolImageTexture}, }; // Symbol Text & Icon -const std::vector - ShaderInfo::uniformBlocks = { +using SymbolTextAndIconShaderInfo = ShaderInfo; + +const std::vector SymbolTextAndIconShaderInfo::uniformBlocks = { UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, }; -const std::vector ShaderInfo::attributes = - { +const std::vector SymbolTextAndIconShaderInfo::attributes = { AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, AttributeInfo{"a_data", idSymbolDataVertexAttribute}, AttributeInfo{"a_projected_pos", idSymbolProjectedPosVertexAttribute}, @@ -442,7 +472,7 @@ const std::vector ShaderInfo ShaderInfo::textures = { +const std::vector SymbolTextAndIconShaderInfo::textures = { TextureInfo{"u_texture", idSymbolImageTexture}, TextureInfo{"u_texture_icon", idSymbolImageIconTexture}, }; diff --git a/src/mbgl/shaders/gl/shader_program_gl.cpp b/src/mbgl/shaders/gl/shader_program_gl.cpp index f56920b091b..a5b3a668c4b 100644 --- a/src/mbgl/shaders/gl/shader_program_gl.cpp +++ b/src/mbgl/shaders/gl/shader_program_gl.cpp @@ -88,19 +88,16 @@ ShaderProgramGL::ShaderProgramGL(UniqueProgram&& glProgram_) glProgram(std::move(glProgram_)) {} ShaderProgramGL::ShaderProgramGL(UniqueProgram&& program, - UniformBlockArrayGL&& uniformBlocks_, VertexAttributeArrayGL&& attributes_, SamplerLocationArray&& samplerLocations_) : ShaderProgramBase(), glProgram(std::move(program)), - uniformBlocks(std::move(uniformBlocks_)), vertexAttributes(std::move(attributes_)), samplerLocations(std::move(samplerLocations_)) {} ShaderProgramGL::ShaderProgramGL(ShaderProgramGL&& other) : ShaderProgramBase(std::forward(other)), glProgram(std::move(other.glProgram)), - uniformBlocks(std::move(other.uniformBlocks)), vertexAttributes(std::move(other.vertexAttributes)), samplerLocations(std::move(other.samplerLocations)) {} @@ -143,7 +140,6 @@ std::shared_ptr ShaderProgramGL::create( context.getObserver().onPostCompileShader( programParameters.getProgramType(), gfx::Backend::Type::OpenGL, additionalDefines); - UniformBlockArrayGL uniformBlocks; for (const auto& blockInfo : uniformBlocksInfo) { GLint index = MBGL_CHECK_ERROR(glGetUniformBlockIndex(program, blockInfo.name.data())); GLint size = 0; @@ -151,7 +147,6 @@ std::shared_ptr ShaderProgramGL::create( assert(size > 0); GLint binding = static_cast(blockInfo.binding); MBGL_CHECK_ERROR(glUniformBlockBinding(program, index, binding)); - uniformBlocks.set(blockInfo.id, binding, size); } SamplerLocationArray samplerLocations; @@ -182,8 +177,7 @@ std::shared_ptr ShaderProgramGL::create( addAttr(attrs, attributesInfo[location].id, location, length, size, glType); } - return std::make_shared( - std::move(program), std::move(uniformBlocks), std::move(attrs), std::move(samplerLocations)); + return std::make_shared(std::move(program), std::move(attrs), std::move(samplerLocations)); } catch (const std::exception& e) { context.getObserver().onShaderCompileFailed( programParameters.getProgramType(), gfx::Backend::Type::OpenGL, additionalDefines); diff --git a/src/mbgl/shaders/mtl/background.cpp b/src/mbgl/shaders/mtl/background.cpp index 04a284c0d13..2b9e8ab91cb 100644 --- a/src/mbgl/shaders/mtl/background.cpp +++ b/src/mbgl/shaders/mtl/background.cpp @@ -9,10 +9,6 @@ namespace shaders { using BackgroundShaderSource = ShaderSource; -const std::array BackgroundShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{false, true, sizeof(BackgroundPropsUBO), idBackgroundPropsUBO}, -}; const std::array BackgroundShaderSource::attributes = { AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; @@ -23,11 +19,6 @@ const std::array BackgroundShaderSource::textures = {}; using BackgroundPatternShaderSource = ShaderSource; -const std::array BackgroundPatternShaderSource::uniforms = { - UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{true, true, sizeof(BackgroundPatternPropsUBO), idBackgroundPropsUBO}, -}; const std::array BackgroundPatternShaderSource::attributes = { AttributeInfo{backgroundUBOCount + 0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; diff --git a/src/mbgl/shaders/mtl/circle.cpp b/src/mbgl/shaders/mtl/circle.cpp index 1e2898afe77..121d4a6baf2 100644 --- a/src/mbgl/shaders/mtl/circle.cpp +++ b/src/mbgl/shaders/mtl/circle.cpp @@ -6,11 +6,6 @@ namespace shaders { using CircleShaderSource = ShaderSource; -const std::array CircleShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(CircleDrawableUBO), idCircleDrawableUBO}, - UniformBlockInfo{true, true, sizeof(CircleEvaluatedPropsUBO), idCircleEvaluatedPropsUBO}, -}; const std::array CircleShaderSource::attributes = { AttributeInfo{circleUBOCount + 0, gfx::AttributeDataType::Short2, idCirclePosVertexAttribute}, AttributeInfo{circleUBOCount + 1, gfx::AttributeDataType::Float4, idCircleColorVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/clipping_mask.cpp b/src/mbgl/shaders/mtl/clipping_mask.cpp index 52ba6e0ba9a..be572874a92 100644 --- a/src/mbgl/shaders/mtl/clipping_mask.cpp +++ b/src/mbgl/shaders/mtl/clipping_mask.cpp @@ -5,9 +5,6 @@ namespace shaders { using ClippingMaskShaderSource = ShaderSource; -const std::array ClippingMaskShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(ClipUBO), idClippingMaskUBO}, -}; const std::array ClippingMaskShaderSource::attributes = { AttributeInfo{clippingMaskUBOCount + 0, gfx::AttributeDataType::Float3, idClippingMaskPosVertexAttribute}, }; diff --git a/src/mbgl/shaders/mtl/collision.cpp b/src/mbgl/shaders/mtl/collision.cpp index 2a7a18d200b..35e4792e6a3 100644 --- a/src/mbgl/shaders/mtl/collision.cpp +++ b/src/mbgl/shaders/mtl/collision.cpp @@ -9,10 +9,6 @@ namespace shaders { using CollisionBoxShaderSource = ShaderSource; -const std::array CollisionBoxShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, - UniformBlockInfo{true, false, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, -}; const std::array CollisionBoxShaderSource::attributes = { AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, @@ -27,10 +23,6 @@ const std::array CollisionBoxShaderSource::textures = {}; using CollisionCircleShaderSource = ShaderSource; -const std::array CollisionCircleShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, -}; const std::array CollisionCircleShaderSource::attributes = { AttributeInfo{collisionUBOCount + 0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, AttributeInfo{collisionUBOCount + 1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp index 314bd5c7374..849d868440c 100644 --- a/src/mbgl/shaders/mtl/custom_symbol_icon.cpp +++ b/src/mbgl/shaders/mtl/custom_symbol_icon.cpp @@ -6,9 +6,6 @@ namespace shaders { using CustomSymbolIconShaderSource = ShaderSource; -const std::array CustomSymbolIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, -}; const std::array CustomSymbolIconShaderSource::attributes = { AttributeInfo{customSymbolUBOCount + 0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, AttributeInfo{customSymbolUBOCount + 1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/debug.cpp b/src/mbgl/shaders/mtl/debug.cpp index 8e8918dd55b..ffebb0d206f 100644 --- a/src/mbgl/shaders/mtl/debug.cpp +++ b/src/mbgl/shaders/mtl/debug.cpp @@ -6,9 +6,6 @@ namespace shaders { using DebugShaderSource = ShaderSource; -const std::array DebugShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(DebugUBO), idDebugUBO}, -}; const std::array DebugShaderSource::attributes = { AttributeInfo{debugUBOCount + 0, gfx::AttributeDataType::Short2, idDebugPosVertexAttribute}, }; diff --git a/src/mbgl/shaders/mtl/fill.cpp b/src/mbgl/shaders/mtl/fill.cpp index dc6dd267609..20fce1316a3 100644 --- a/src/mbgl/shaders/mtl/fill.cpp +++ b/src/mbgl/shaders/mtl/fill.cpp @@ -9,10 +9,6 @@ namespace shaders { using FillShaderSource = ShaderSource; -const std::array FillShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(FillDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::Float4, idFillColorVertexAttribute}, @@ -25,11 +21,6 @@ const std::array FillShaderSource::textures = {}; using FillOutlineShaderSource = ShaderSource; -const std::array FillOutlineShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlineDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillOutlineShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::Float4, idFillOutlineColorVertexAttribute}, @@ -42,12 +33,6 @@ const std::array FillOutlineShaderSource::textures = {}; using FillPatternShaderSource = ShaderSource; -const std::array FillPatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillPatternDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillPatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillPatternShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, @@ -63,12 +48,6 @@ const std::array FillPatternShaderSource::textures = { using FillOutlinePatternShaderSource = ShaderSource; -const std::array FillOutlinePatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillOutlinePatternShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, @@ -85,11 +64,6 @@ const std::array FillOutlinePatternShaderSource::textures = { using FillOutlineTriangulatedShaderSource = ShaderSource; -const std::array FillOutlineTriangulatedShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillOutlineTriangulatedShaderSource::attributes = { AttributeInfo{fillUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{fillUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/fill_extrusion.cpp b/src/mbgl/shaders/mtl/fill_extrusion.cpp index 133c813d1e0..c39a9620aa8 100644 --- a/src/mbgl/shaders/mtl/fill_extrusion.cpp +++ b/src/mbgl/shaders/mtl/fill_extrusion.cpp @@ -9,10 +9,6 @@ namespace shaders { using FillExtrusionShaderSource = ShaderSource; -const std::array FillExtrusionShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, -}; const std::array FillExtrusionShaderSource::attributes = { AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, @@ -27,12 +23,6 @@ const std::array FillExtrusionShaderSource::textures = {}; using FillExtrusionPatternShaderSource = ShaderSource; -const std::array FillExtrusionPatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, -}; const std::array FillExtrusionPatternShaderSource::attributes = { AttributeInfo{fillExtrusionUBOCount + 0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, AttributeInfo{fillExtrusionUBOCount + 1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/heatmap.cpp b/src/mbgl/shaders/mtl/heatmap.cpp index 27b234757a6..45351bb324e 100644 --- a/src/mbgl/shaders/mtl/heatmap.cpp +++ b/src/mbgl/shaders/mtl/heatmap.cpp @@ -6,10 +6,6 @@ namespace shaders { using HeatmapShaderSource = ShaderSource; -const std::array HeatmapShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(HeatmapDrawableUBO), idHeatmapDrawableUBO}, - UniformBlockInfo{true, true, sizeof(HeatmapEvaluatedPropsUBO), idHeatmapEvaluatedPropsUBO}, -}; const std::array HeatmapShaderSource::attributes = { AttributeInfo{heatmapUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, AttributeInfo{heatmapUBOCount + 1, gfx::AttributeDataType::Float2, idHeatmapWeightVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/heatmap_texture.cpp b/src/mbgl/shaders/mtl/heatmap_texture.cpp index c0c16308910..28fb4e54a6f 100644 --- a/src/mbgl/shaders/mtl/heatmap_texture.cpp +++ b/src/mbgl/shaders/mtl/heatmap_texture.cpp @@ -6,10 +6,6 @@ namespace shaders { using HeatmapTextureShaderSource = ShaderSource; -const std::array HeatmapTextureShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, -}; const std::array HeatmapTextureShaderSource::attributes = { AttributeInfo{heatmapTextureUBOCount + 0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, }; diff --git a/src/mbgl/shaders/mtl/hillshade.cpp b/src/mbgl/shaders/mtl/hillshade.cpp index 0a7daa68eaa..d0695022895 100644 --- a/src/mbgl/shaders/mtl/hillshade.cpp +++ b/src/mbgl/shaders/mtl/hillshade.cpp @@ -6,11 +6,6 @@ namespace shaders { using HillshadeShaderSource = ShaderSource; -const std::array HillshadeShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, - UniformBlockInfo{false, true, sizeof(HillshadeTilePropsUBO), idHillshadeTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO}, -}; const std::array HillshadeShaderSource::attributes = { AttributeInfo{hillshadeUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, AttributeInfo{hillshadeUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/hillshade_prepare.cpp b/src/mbgl/shaders/mtl/hillshade_prepare.cpp index 49b9f7a6507..3cd1571deca 100644 --- a/src/mbgl/shaders/mtl/hillshade_prepare.cpp +++ b/src/mbgl/shaders/mtl/hillshade_prepare.cpp @@ -6,10 +6,6 @@ namespace shaders { using HillshadePrepareShaderSource = ShaderSource; -const std::array HillshadePrepareShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, - UniformBlockInfo{true, true, sizeof(HillshadePrepareTilePropsUBO), idHillshadePrepareTilePropsUBO}, -}; const std::array HillshadePrepareShaderSource::attributes = { AttributeInfo{hillshadePrepareUBOCount + 0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, AttributeInfo{hillshadePrepareUBOCount + 1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/line.cpp b/src/mbgl/shaders/mtl/line.cpp index afb607c5c86..028085a5f4c 100644 --- a/src/mbgl/shaders/mtl/line.cpp +++ b/src/mbgl/shaders/mtl/line.cpp @@ -9,12 +9,6 @@ namespace shaders { using LineShaderSource = ShaderSource; -const std::array LineShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LineDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, - UniformBlockInfo{true, true, sizeof(LineExpressionUBO), idLineExpressionUBO}, -}; const std::array LineShaderSource::attributes = { AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, @@ -32,11 +26,6 @@ const std::array LineShaderSource::textures = {}; using LineGradientShaderSource = ShaderSource; -const std::array LineGradientShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LineGradientDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, -}; const std::array LineGradientShaderSource::attributes = { AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, @@ -55,13 +44,6 @@ const std::array LineGradientShaderSource::textures = { using LinePatternShaderSource = ShaderSource; -const std::array LinePatternShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LinePatternDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{false, true, sizeof(LinePatternTilePropsUBO), idLineTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, - UniformBlockInfo{true, true, sizeof(LineExpressionUBO), idLineExpressionUBO}, -}; const std::array LinePatternShaderSource::attributes = { AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, @@ -82,13 +64,6 @@ const std::array LinePatternShaderSource::textures = { using LineSDFShaderSource = ShaderSource; -const std::array LineSDFShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LineSDFDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{false, true, sizeof(LineSDFTilePropsUBO), idLineTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, - UniformBlockInfo{true, true, sizeof(LineExpressionUBO), idLineExpressionUBO}, -}; const std::array LineSDFShaderSource::attributes = { AttributeInfo{lineUBOCount + 0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{lineUBOCount + 1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/raster.cpp b/src/mbgl/shaders/mtl/raster.cpp index f9ae0c00390..a3b5e1cb10d 100644 --- a/src/mbgl/shaders/mtl/raster.cpp +++ b/src/mbgl/shaders/mtl/raster.cpp @@ -6,10 +6,6 @@ namespace shaders { using RasterShaderSource = ShaderSource; -const std::array RasterShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(RasterDrawableUBO), idRasterDrawableUBO}, - UniformBlockInfo{true, true, sizeof(RasterEvaluatedPropsUBO), idRasterEvaluatedPropsUBO}, -}; const std::array RasterShaderSource::attributes = { AttributeInfo{rasterUBOCount + 0, gfx::AttributeDataType::Short2, idRasterPosVertexAttribute}, AttributeInfo{rasterUBOCount + 1, gfx::AttributeDataType::Short2, idRasterTexturePosVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/shader_program.cpp b/src/mbgl/shaders/mtl/shader_program.cpp index 1528fc8623e..1f525d8921c 100644 --- a/src/mbgl/shaders/mtl/shader_program.cpp +++ b/src/mbgl/shaders/mtl/shader_program.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -190,7 +189,6 @@ void ShaderProgram::initAttribute(const shaders::AttributeInfo& info) { // Indexes must be unique, if there's a conflict check the `attributes` array in the shader vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); instanceAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); - uniformBlocks.visit([&](const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); #endif vertexAttributes.set(info.id, index, info.dataType, 1); } @@ -202,26 +200,10 @@ void ShaderProgram::initInstanceAttribute(const shaders::AttributeInfo& info) { // Indexes must not be reused by regular attributes or uniform blocks // More than one instance attribute can have the same index, if they share the block vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); - uniformBlocks.visit([&](const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); #endif instanceAttributes.set(info.id, index, info.dataType, 1); } -void ShaderProgram::initUniformBlock(const shaders::UniformBlockInfo& info) { - const auto index = static_cast(info.index); -#if !defined(NDEBUG) - // Indexes must be unique, if there's a conflict check the `attributes` array in the shader - vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); - instanceAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); - uniformBlocks.visit([&](const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); -#endif - if (const auto& block_ = uniformBlocks.set(info.id, index, info.size)) { - auto& block = static_cast(*block_); - block.setBindVertex(info.vertex); - block.setBindFragment(info.fragment); - } -} - void ShaderProgram::initTexture(const shaders::TextureInfo& info) { assert(info.id < textureBindings.size()); if (info.id >= textureBindings.size()) { diff --git a/src/mbgl/shaders/mtl/symbol.cpp b/src/mbgl/shaders/mtl/symbol.cpp index 8c5a1608157..2d1d51e6aca 100644 --- a/src/mbgl/shaders/mtl/symbol.cpp +++ b/src/mbgl/shaders/mtl/symbol.cpp @@ -9,12 +9,6 @@ namespace shaders { using SymbolIconShaderSource = ShaderSource; -const std::array SymbolIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; const std::array SymbolIconShaderSource::attributes = { // always attributes AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, @@ -35,12 +29,6 @@ const std::array SymbolIconShaderSource::textures = { using SymbolSDFIconShaderSource = ShaderSource; -const std::array SymbolSDFIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; const std::array SymbolSDFIconShaderSource::attributes = { // always attributes AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, @@ -65,12 +53,6 @@ const std::array SymbolSDFIconShaderSource::textures = { using SymbolTextAndIconShaderSource = ShaderSource; -const std::array SymbolTextAndIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; const std::array SymbolTextAndIconShaderSource::attributes = { // always attributes AttributeInfo{symbolUBOCount + 0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, diff --git a/src/mbgl/shaders/mtl/widevector.cpp b/src/mbgl/shaders/mtl/widevector.cpp index 1afee2968d1..fec44118d29 100644 --- a/src/mbgl/shaders/mtl/widevector.cpp +++ b/src/mbgl/shaders/mtl/widevector.cpp @@ -6,10 +6,6 @@ namespace shaders { using WideVectorShaderSource = ShaderSource; -const std::array WideVectorShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(WideVectorUniformsUBO), idWideVectorUniformsUBO}, - UniformBlockInfo{true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO}, -}; const std::array WideVectorShaderSource::attributes = { AttributeInfo{wideVectorUBOCount + 0, gfx::AttributeDataType::Float3, idWideVectorScreenPos}, AttributeInfo{wideVectorUBOCount + 1, gfx::AttributeDataType::Float4, idWideVectorColor}, diff --git a/src/mbgl/shaders/vulkan/background.cpp b/src/mbgl/shaders/vulkan/background.cpp index f8aaa0e0b70..c3aec95e76d 100644 --- a/src/mbgl/shaders/vulkan/background.cpp +++ b/src/mbgl/shaders/vulkan/background.cpp @@ -10,10 +10,6 @@ namespace shaders { using BackgroundShaderSource = ShaderSource; -const std::array BackgroundShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(BackgroundDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{false, true, sizeof(BackgroundPropsUBO), idBackgroundPropsUBO}, -}; const std::array BackgroundShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; @@ -24,11 +20,6 @@ const std::array BackgroundShaderSource::textures = {}; using BackgroundPatternShaderSource = ShaderSource; -const std::array BackgroundPatternShaderSource::uniforms = { - UniformBlockInfo{false, true, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(BackgroundPatternDrawableUBO), idBackgroundDrawableUBO}, - UniformBlockInfo{true, true, sizeof(BackgroundPatternPropsUBO), idBackgroundPropsUBO}, -}; const std::array BackgroundPatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float3, idBackgroundPosVertexAttribute}, }; diff --git a/src/mbgl/shaders/vulkan/circle.cpp b/src/mbgl/shaders/vulkan/circle.cpp index 9e079d984c4..61213640484 100644 --- a/src/mbgl/shaders/vulkan/circle.cpp +++ b/src/mbgl/shaders/vulkan/circle.cpp @@ -7,11 +7,6 @@ namespace shaders { using CircleShaderSource = ShaderSource; -const std::array CircleShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(CircleDrawableUBO), idCircleDrawableUBO}, - UniformBlockInfo{true, true, sizeof(CircleEvaluatedPropsUBO), idCircleEvaluatedPropsUBO}, -}; const std::array CircleShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idCirclePosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float4, idCircleColorVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/clipping_mask.cpp b/src/mbgl/shaders/vulkan/clipping_mask.cpp index f26fc8669f5..df96133cf49 100644 --- a/src/mbgl/shaders/vulkan/clipping_mask.cpp +++ b/src/mbgl/shaders/vulkan/clipping_mask.cpp @@ -5,7 +5,6 @@ namespace shaders { using ClippingMaskShaderSource = ShaderSource; -const std::array ClippingMaskShaderSource::uniforms = {}; const std::array ClippingMaskShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idClippingMaskPosVertexAttribute}, }; diff --git a/src/mbgl/shaders/vulkan/collision.cpp b/src/mbgl/shaders/vulkan/collision.cpp index 6c11c4de301..343045dd5a6 100644 --- a/src/mbgl/shaders/vulkan/collision.cpp +++ b/src/mbgl/shaders/vulkan/collision.cpp @@ -10,10 +10,6 @@ namespace shaders { using CollisionBoxShaderSource = ShaderSource; -const std::array CollisionBoxShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, - UniformBlockInfo{true, false, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, -}; const std::array CollisionBoxShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, @@ -28,10 +24,6 @@ const std::array CollisionBoxShaderSource::textures = {}; using CollisionCircleShaderSource = ShaderSource; -const std::array CollisionCircleShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CollisionDrawableUBO), idCollisionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(CollisionTilePropsUBO), idCollisionTilePropsUBO}, -}; const std::array CollisionCircleShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idCollisionPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idCollisionAnchorPosVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp b/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp index 4b6cf37d561..fb90ae95dcf 100644 --- a/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp +++ b/src/mbgl/shaders/vulkan/custom_symbol_icon.cpp @@ -7,9 +7,6 @@ namespace shaders { using CustomSymbolIconShaderSource = ShaderSource; -const std::array CustomSymbolIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(CustomSymbolIconDrawableUBO), idCustomSymbolDrawableUBO}, -}; const std::array CustomSymbolIconShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float2, idCustomSymbolPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float2, idCustomSymbolTexVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/debug.cpp b/src/mbgl/shaders/vulkan/debug.cpp index 761b12dd186..c5df1087c30 100644 --- a/src/mbgl/shaders/vulkan/debug.cpp +++ b/src/mbgl/shaders/vulkan/debug.cpp @@ -7,9 +7,6 @@ namespace shaders { using DebugShaderSource = ShaderSource; -const std::array DebugShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(DebugUBO), idDebugUBO}, -}; const std::array DebugShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idDebugPosVertexAttribute}, }; diff --git a/src/mbgl/shaders/vulkan/fill.cpp b/src/mbgl/shaders/vulkan/fill.cpp index 1df2fd742c0..a870abf2c46 100644 --- a/src/mbgl/shaders/vulkan/fill.cpp +++ b/src/mbgl/shaders/vulkan/fill.cpp @@ -10,10 +10,6 @@ namespace shaders { using FillShaderSource = ShaderSource; -const std::array FillShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(FillDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float4, idFillColorVertexAttribute}, @@ -26,11 +22,6 @@ const std::array FillShaderSource::textures = {}; using FillOutlineShaderSource = ShaderSource; -const std::array FillOutlineShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlineDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillOutlineShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float4, idFillOutlineColorVertexAttribute}, @@ -43,12 +34,6 @@ const std::array FillOutlineShaderSource::textures = {}; using FillPatternShaderSource = ShaderSource; -const std::array FillPatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillPatternDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillPatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillPatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, @@ -64,12 +49,6 @@ const std::array FillPatternShaderSource::textures = { using FillOutlinePatternShaderSource = ShaderSource; -const std::array FillOutlinePatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlinePatternDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillOutlinePatternTilePropsUBO), idFillTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillOutlinePatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UShort4, idFillPatternFromVertexAttribute}, @@ -86,11 +65,6 @@ const std::array FillOutlinePatternShaderSource::textures = { using FillOutlineTriangulatedShaderSource = ShaderSource; -const std::array FillOutlineTriangulatedShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillOutlineTriangulatedDrawableUBO), idFillDrawableUBO}, - UniformBlockInfo{false, true, sizeof(FillEvaluatedPropsUBO), idFillEvaluatedPropsUBO}, -}; const std::array FillOutlineTriangulatedShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/fill_extrusion.cpp b/src/mbgl/shaders/vulkan/fill_extrusion.cpp index d73eeddd5bd..e7f600e2b4f 100644 --- a/src/mbgl/shaders/vulkan/fill_extrusion.cpp +++ b/src/mbgl/shaders/vulkan/fill_extrusion.cpp @@ -10,10 +10,6 @@ namespace shaders { using FillExtrusionShaderSource = ShaderSource; -const std::array FillExtrusionShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, -}; const std::array FillExtrusionShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, @@ -28,12 +24,6 @@ const std::array FillExtrusionShaderSource::textures = {}; using FillExtrusionPatternShaderSource = ShaderSource; -const std::array FillExtrusionPatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(FillExtrusionDrawableUBO), idFillExtrusionDrawableUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionTilePropsUBO), idFillExtrusionTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(FillExtrusionPropsUBO), idFillExtrusionPropsUBO}, -}; const std::array FillExtrusionPatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idFillExtrusionPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short4, idFillExtrusionNormalEdVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/heatmap.cpp b/src/mbgl/shaders/vulkan/heatmap.cpp index 69688327c6b..203af787ea5 100644 --- a/src/mbgl/shaders/vulkan/heatmap.cpp +++ b/src/mbgl/shaders/vulkan/heatmap.cpp @@ -7,10 +7,6 @@ namespace shaders { using HeatmapShaderSource = ShaderSource; -const std::array HeatmapShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(HeatmapDrawableUBO), idHeatmapDrawableUBO}, - UniformBlockInfo{true, true, sizeof(HeatmapEvaluatedPropsUBO), idHeatmapEvaluatedPropsUBO}, -}; const std::array HeatmapShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float2, idHeatmapWeightVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/heatmap_texture.cpp b/src/mbgl/shaders/vulkan/heatmap_texture.cpp index 16b9bdd99aa..be27a0fa07c 100644 --- a/src/mbgl/shaders/vulkan/heatmap_texture.cpp +++ b/src/mbgl/shaders/vulkan/heatmap_texture.cpp @@ -7,10 +7,6 @@ namespace shaders { using HeatmapTextureShaderSource = ShaderSource; -const std::array HeatmapTextureShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, true, sizeof(HeatmapTexturePropsUBO), idHeatmapTexturePropsUBO}, -}; const std::array HeatmapTextureShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idHeatmapPosVertexAttribute}, }; diff --git a/src/mbgl/shaders/vulkan/hillshade.cpp b/src/mbgl/shaders/vulkan/hillshade.cpp index fa85290bdb4..ed78938d67a 100644 --- a/src/mbgl/shaders/vulkan/hillshade.cpp +++ b/src/mbgl/shaders/vulkan/hillshade.cpp @@ -7,11 +7,6 @@ namespace shaders { using HillshadeShaderSource = ShaderSource; -const std::array HillshadeShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(HillshadeDrawableUBO), idHillshadeDrawableUBO}, - UniformBlockInfo{false, true, sizeof(HillshadeTilePropsUBO), idHillshadeTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(HillshadeEvaluatedPropsUBO), idHillshadeEvaluatedPropsUBO}, -}; const std::array HillshadeShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/hillshade_prepare.cpp b/src/mbgl/shaders/vulkan/hillshade_prepare.cpp index 04cd8f9eac3..1999e2f73fc 100644 --- a/src/mbgl/shaders/vulkan/hillshade_prepare.cpp +++ b/src/mbgl/shaders/vulkan/hillshade_prepare.cpp @@ -7,10 +7,6 @@ namespace shaders { using HillshadePrepareShaderSource = ShaderSource; -const std::array HillshadePrepareShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(HillshadePrepareDrawableUBO), idHillshadePrepareDrawableUBO}, - UniformBlockInfo{true, true, sizeof(HillshadePrepareTilePropsUBO), idHillshadePrepareTilePropsUBO}, -}; const std::array HillshadePrepareShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idHillshadePosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idHillshadeTexturePosVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/line.cpp b/src/mbgl/shaders/vulkan/line.cpp index 607b3e164a8..8ddfcb8b589 100644 --- a/src/mbgl/shaders/vulkan/line.cpp +++ b/src/mbgl/shaders/vulkan/line.cpp @@ -10,11 +10,6 @@ namespace shaders { using LineShaderSource = ShaderSource; -const std::array LineShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LineDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, -}; const std::array LineShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, @@ -32,11 +27,6 @@ const std::array LineShaderSource::textures = {}; using LineGradientShaderSource = ShaderSource; -const std::array LineGradientShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LineGradientDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, -}; const std::array LineGradientShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, @@ -55,12 +45,6 @@ const std::array LineGradientShaderSource::textures = { using LinePatternShaderSource = ShaderSource; -const std::array LinePatternShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LinePatternDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{false, true, sizeof(LinePatternTilePropsUBO), idLineTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, -}; const std::array LinePatternShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, @@ -81,12 +65,6 @@ const std::array LinePatternShaderSource::textures = { using LineSDFShaderSource = ShaderSource; -const std::array LineSDFShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(LineSDFDrawableUBO), idLineDrawableUBO}, - UniformBlockInfo{false, true, sizeof(LineSDFTilePropsUBO), idLineTilePropsUBO}, - UniformBlockInfo{true, true, sizeof(LineEvaluatedPropsUBO), idLineEvaluatedPropsUBO}, -}; const std::array LineSDFShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idLinePosNormalVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::UByte4, idLineDataVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/location_indicator.cpp b/src/mbgl/shaders/vulkan/location_indicator.cpp index c0c4c6f8462..2eb9f8e87b4 100644 --- a/src/mbgl/shaders/vulkan/location_indicator.cpp +++ b/src/mbgl/shaders/vulkan/location_indicator.cpp @@ -10,9 +10,6 @@ namespace shaders { using LocationIndicatorShaderSource = ShaderSource; -const std::array LocationIndicatorShaderSource::uniforms = { - UniformBlockInfo{true, true, sizeof(LocationIndicatorDrawableUBO), idLocationIndicatorDrawableUBO}, -}; const std::array LocationIndicatorShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute}, }; @@ -24,9 +21,6 @@ const std::array LocationIndicatorShaderSource::textures = {}; using LocationIndicatorShaderTexturedSource = ShaderSource; -const std::array LocationIndicatorShaderTexturedSource::uniforms = { - UniformBlockInfo{true, false, sizeof(LocationIndicatorDrawableUBO), idLocationIndicatorDrawableUBO}, -}; const std::array LocationIndicatorShaderTexturedSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float2, idCommonPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Float2, idCommonTexVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/raster.cpp b/src/mbgl/shaders/vulkan/raster.cpp index 177c3579d7b..132fc61356a 100644 --- a/src/mbgl/shaders/vulkan/raster.cpp +++ b/src/mbgl/shaders/vulkan/raster.cpp @@ -7,10 +7,6 @@ namespace shaders { using RasterShaderSource = ShaderSource; -const std::array RasterShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(RasterDrawableUBO), idRasterDrawableUBO}, - UniformBlockInfo{true, true, sizeof(RasterEvaluatedPropsUBO), idRasterEvaluatedPropsUBO}, -}; const std::array RasterShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Short2, idRasterPosVertexAttribute}, AttributeInfo{1, gfx::AttributeDataType::Short2, idRasterTexturePosVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/shader_program.cpp b/src/mbgl/shaders/vulkan/shader_program.cpp index 14052e1b995..a0b29b5ebaf 100644 --- a/src/mbgl/shaders/vulkan/shader_program.cpp +++ b/src/mbgl/shaders/vulkan/shader_program.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -240,7 +239,6 @@ void ShaderProgram::initAttribute(const shaders::AttributeInfo& info) { // Indexes must be unique, if there's a conflict check the `attributes` array in the shader vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); instanceAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); - uniformBlocks.visit([&](const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); #endif vertexAttributes.set(info.id, index, info.dataType, 1); } @@ -252,24 +250,10 @@ void ShaderProgram::initInstanceAttribute(const shaders::AttributeInfo& info) { // Indexes must not be reused by regular attributes or uniform blocks // More than one instance attribute can have the same index, if they share the block vertexAttributes.visitAttributes([&](const gfx::VertexAttribute& attrib) { assert(attrib.getIndex() != index); }); - uniformBlocks.visit([&](const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); #endif instanceAttributes.set(info.id, index, info.dataType, 1); } -void ShaderProgram::initUniformBlock(const shaders::UniformBlockInfo& info) { - const auto index = static_cast(info.index); -#if !defined(NDEBUG) - // Indexes must be unique, if there's a conflict check the `attributes` array in the shader - uniformBlocks.visit([&](const gfx::UniformBlock& block) { assert(block.getIndex() != index); }); -#endif - if (const auto& block_ = uniformBlocks.set(info.id, index, info.size)) { - auto& block = static_cast(*block_); - block.setBindVertex(info.vertex); - block.setBindFragment(info.fragment); - } -} - void ShaderProgram::initTexture(const shaders::TextureInfo& info) { assert(info.id < textureBindings.size()); if (info.id >= textureBindings.size()) { diff --git a/src/mbgl/shaders/vulkan/symbol.cpp b/src/mbgl/shaders/vulkan/symbol.cpp index 068b4cb51ac..b2a39807109 100644 --- a/src/mbgl/shaders/vulkan/symbol.cpp +++ b/src/mbgl/shaders/vulkan/symbol.cpp @@ -10,12 +10,6 @@ namespace shaders { using SymbolIconShaderSource = ShaderSource; -const std::array SymbolIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; const std::array SymbolIconShaderSource::attributes = { // always attributes AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, @@ -36,12 +30,6 @@ const std::array SymbolIconShaderSource::textures = { using SymbolSDFIconShaderSource = ShaderSource; -const std::array SymbolSDFIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; const std::array SymbolSDFIconShaderSource::attributes = { // always attributes AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, @@ -66,12 +54,6 @@ const std::array SymbolSDFIconShaderSource::textures = { using SymbolTextAndIconShaderSource = ShaderSource; -const std::array SymbolTextAndIconShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(GlobalPaintParamsUBO), idGlobalPaintParamsUBO}, - UniformBlockInfo{true, false, sizeof(SymbolDrawableUBO), idSymbolDrawableUBO}, - UniformBlockInfo{false, true, sizeof(SymbolTilePropsUBO), idSymbolTilePropsUBO}, - UniformBlockInfo{false, true, sizeof(SymbolEvaluatedPropsUBO), idSymbolEvaluatedPropsUBO}, -}; const std::array SymbolTextAndIconShaderSource::attributes = { // always attributes AttributeInfo{0, gfx::AttributeDataType::Short4, idSymbolPosOffsetVertexAttribute}, diff --git a/src/mbgl/shaders/vulkan/widevector.cpp b/src/mbgl/shaders/vulkan/widevector.cpp index d1200ab88fd..9fb09e8b604 100644 --- a/src/mbgl/shaders/vulkan/widevector.cpp +++ b/src/mbgl/shaders/vulkan/widevector.cpp @@ -7,10 +7,6 @@ namespace shaders { using WideVectorShaderSource = ShaderSource; -const std::array WideVectorShaderSource::uniforms = { - UniformBlockInfo{true, false, sizeof(WideVectorUniformsUBO), idWideVectorUniformsUBO}, - UniformBlockInfo{true, false, sizeof(WideVectorUniformWideVecUBO), idWideVectorUniformWideVecUBO}, -}; const std::array WideVectorShaderSource::attributes = { AttributeInfo{0, gfx::AttributeDataType::Float3, idWideVectorScreenPos}, AttributeInfo{1, gfx::AttributeDataType::Float4, idWideVectorColor}, diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index e9b2da70cae..351258aa618 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -119,8 +119,8 @@ class LineDrawableTweaker : public gfx::DrawableTweaker { /* .width_t = */ 0.f, /* .pad1 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context, true, false); - drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context, true, true); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); @@ -187,8 +187,8 @@ class WideVectorDrawableTweaker : public gfx::DrawableTweaker { /* .pad1 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idWideVectorUniformsUBO, &uniform, parameters.context, true, false); - drawableUniforms.createOrUpdate(idWideVectorUniformWideVecUBO, &wideVec, parameters.context, true, false); + drawableUniforms.createOrUpdate(idWideVectorUniformsUBO, &uniform, parameters.context); + drawableUniforms.createOrUpdate(idWideVectorUniformWideVecUBO, &wideVec, parameters.context); }; private: @@ -230,8 +230,8 @@ class FillDrawableTweaker : public gfx::DrawableTweaker { /* .from_scale = */ 0.f, /* .to_scale = */ 0.f}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idFillDrawableUBO, &fillDrawableUBO, parameters.context, true, false); - drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context, true, true); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &fillDrawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context); }; private: @@ -282,7 +282,7 @@ class SymbolDrawableTweaker : public gfx::DrawableTweaker { /* .pad3 = */ 0}; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idCustomSymbolDrawableUBO, &drawableUBO, parameters.context, true, false); + drawableUniforms.createOrUpdate(idCustomSymbolDrawableUBO, &drawableUBO, parameters.context); }; private: diff --git a/src/mbgl/vulkan/context.cpp b/src/mbgl/vulkan/context.cpp index 0f71d20875d..daa98ce7e51 100644 --- a/src/mbgl/vulkan/context.cpp +++ b/src/mbgl/vulkan/context.cpp @@ -113,11 +113,11 @@ void Context::initFrameResources() { (void)getDummyTexture(); buildUniformDescriptorSetLayout( - globalUniformDescriptorSetLayout, shaders::globalUBOCount, "GlobalUniformDescriptorSetLayout"); + globalUniformDescriptorSetLayout, 0, shaders::globalUBOCount, "GlobalUniformDescriptorSetLayout"); buildUniformDescriptorSetLayout( - layerUniformDescriptorSetLayout, shaders::maxUBOCountPerLayer, "LayerUniformDescriptorSetLayout"); + layerUniformDescriptorSetLayout, shaders::layerUBOStartId, shaders::maxUBOCountPerLayer, "LayerUniformDescriptorSetLayout"); buildUniformDescriptorSetLayout( - drawableUniformDescriptorSetLayout, shaders::maxUBOCountPerDrawable, "DrawableUniformDescriptorSetLayout"); + drawableUniformDescriptorSetLayout, shaders::globalUBOCount, shaders::maxUBOCountPerDrawable, "DrawableUniformDescriptorSetLayout"); buildImageDescriptorSetLayout(); } @@ -445,8 +445,7 @@ void Context::bindGlobalUniformBuffers(gfx::RenderPass& renderPass) const noexce const shaders::GlobalPlatformParamsUBO platformUBO = { /* .rotation0 = */ {cosf(surfaceRotation), -sinf(surfaceRotation)}, /* .rotation1 = */ {sinf(surfaceRotation), cosf(surfaceRotation)}}; - context.globalUniformBuffers.createOrUpdate( - shaders::idGlobalPlatformParamsUBO, &platformUBO, sizeof(platformUBO), context, true, true); + context.globalUniformBuffers.createOrUpdate(shaders::idGlobalPlatformParamsUBO, &platformUBO, sizeof(platformUBO), context); } context.globalUniformBuffers.bindDescriptorSets(renderPassImpl.getEncoder()); @@ -586,13 +585,19 @@ const std::unique_ptr& Context::getDummyTexture() { } void Context::buildUniformDescriptorSetLayout(vk::UniqueDescriptorSetLayout& layout, + size_t uniformStartId, size_t uniformCount, const std::string& name) { std::vector bindings; - const auto stageFlags = vk::ShaderStageFlags() | vk::ShaderStageFlagBits::eVertex | - vk::ShaderStageFlagBits::eFragment; - for (size_t i = 0; i < uniformCount; ++i) { + auto stageFlags = vk::ShaderStageFlags(); + if (uniformStartId + i != shaders::idDrawableReservedFragmentOnlyUBO) { + stageFlags |= vk::ShaderStageFlagBits::eVertex; + } + if (uniformStartId + i != shaders::idDrawableReservedVertexOnlyUBO) { + stageFlags |= vk::ShaderStageFlagBits::eFragment; + } + bindings.push_back(vk::DescriptorSetLayoutBinding() .setBinding(i) .setStageFlags(stageFlags) diff --git a/src/mbgl/vulkan/uniform_buffer.cpp b/src/mbgl/vulkan/uniform_buffer.cpp index 86d94af485d..b01e0facc90 100644 --- a/src/mbgl/vulkan/uniform_buffer.cpp +++ b/src/mbgl/vulkan/uniform_buffer.cpp @@ -40,9 +40,7 @@ void UniformBuffer::update(const void* data, std::size_t size_) { } const std::shared_ptr& UniformBufferArray::set(const size_t id, - std::shared_ptr uniformBuffer, - bool bindVertex, - bool bindFragment) { + std::shared_ptr uniformBuffer) { if (id >= uniformBufferVector.size()) { return nullref; } @@ -56,22 +54,18 @@ const std::shared_ptr& UniformBufferArray::set(const size_t } uniformBufferVector[id] = std::move(uniformBuffer); - if (uniformBufferVector[id]) { - uniformBufferVector[id]->setBindVertex(bindVertex); - uniformBufferVector[id]->setBindFragment(bindFragment); - } return uniformBufferVector[id]; } void UniformBufferArray::createOrUpdate( - const size_t id, const void* data, std::size_t size, gfx::Context& context, bool bindVertex, bool bindFragment) { + const size_t id, const void* data, std::size_t size, gfx::Context& context, bool persistent) { if (descriptorSet) { if (auto& ubo = get(id); !ubo || ubo->getSize() != size) { descriptorSet->markDirty(); } } - gfx::UniformBufferArray::createOrUpdate(id, data, size, context, bindVertex, bindFragment); + gfx::UniformBufferArray::createOrUpdate(id, data, size, context, persistent); } void UniformBufferArray::bindDescriptorSets(CommandEncoder& encoder) { From 33100e3a7cb8fdba119d1b68ee3958fada06be97 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:28:51 +0000 Subject: [PATCH 09/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- include/mbgl/gfx/uniform_buffer.hpp | 6 +- include/mbgl/shaders/gl/shader_program_gl.hpp | 4 +- include/mbgl/shaders/mtl/background.hpp | 2 +- include/mbgl/shaders/mtl/debug.hpp | 2 +- include/mbgl/shaders/mtl/fill.hpp | 4 +- include/mbgl/shaders/mtl/fill_extrusion.hpp | 2 +- .../mbgl/shaders/mtl/hillshade_prepare.hpp | 2 +- include/mbgl/shaders/mtl/line.hpp | 2 +- include/mbgl/shaders/mtl/symbol.hpp | 4 +- include/mbgl/shaders/vulkan/background.hpp | 2 +- include/mbgl/shaders/vulkan/circle.hpp | 2 +- .../shaders/vulkan/custom_symbol_icon.hpp | 2 +- include/mbgl/shaders/vulkan/fill.hpp | 4 +- .../mbgl/shaders/vulkan/fill_extrusion.hpp | 2 +- include/mbgl/shaders/vulkan/line.hpp | 2 +- include/mbgl/shaders/vulkan/symbol.hpp | 2 +- include/mbgl/vulkan/uniform_buffer.hpp | 7 +- src/mbgl/gfx/uniform_buffer.cpp | 13 +- src/mbgl/shaders/gl/shader_info.cpp | 145 +++++++++--------- src/mbgl/vulkan/context.cpp | 15 +- 20 files changed, 111 insertions(+), 113 deletions(-) diff --git a/include/mbgl/gfx/uniform_buffer.hpp b/include/mbgl/gfx/uniform_buffer.hpp index a1d9023b304..d1acdc94ae2 100644 --- a/include/mbgl/gfx/uniform_buffer.hpp +++ b/include/mbgl/gfx/uniform_buffer.hpp @@ -62,12 +62,10 @@ class UniformBufferArray { const std::shared_ptr& get(const size_t id) const; /// Set a new uniform buffer element or replace the existing one. - virtual const std::shared_ptr& set(const size_t id, - std::shared_ptr uniformBuffer); + virtual const std::shared_ptr& set(const size_t id, std::shared_ptr uniformBuffer); /// Create and add a new buffer or update an existing one - void createOrUpdate( - const size_t id, const std::vector& data, gfx::Context&, bool persistent = false); + void createOrUpdate(const size_t id, const std::vector& data, gfx::Context&, bool persistent = false); virtual void createOrUpdate( const size_t id, const void* data, std::size_t size, gfx::Context&, bool persistent = false); template diff --git a/include/mbgl/shaders/gl/shader_program_gl.hpp b/include/mbgl/shaders/gl/shader_program_gl.hpp index cc4c778b648..df370fa17b2 100644 --- a/include/mbgl/shaders/gl/shader_program_gl.hpp +++ b/include/mbgl/shaders/gl/shader_program_gl.hpp @@ -19,9 +19,7 @@ class ShaderProgramGL final : public gfx::ShaderProgramBase { using SamplerLocationArray = std::array, shaders::maxTextureCountPerShader>; ShaderProgramGL(UniqueProgram&& glProgram_); - ShaderProgramGL(UniqueProgram&&, - VertexAttributeArrayGL&& attributes, - SamplerLocationArray&& samplerLocations); + ShaderProgramGL(UniqueProgram&&, VertexAttributeArrayGL&& attributes, SamplerLocationArray&& samplerLocations); ShaderProgramGL(ShaderProgramGL&& other); ~ShaderProgramGL() noexcept override = default; diff --git a/include/mbgl/shaders/mtl/background.hpp b/include/mbgl/shaders/mtl/background.hpp index 3d307ecedc1..cb683aefde7 100644 --- a/include/mbgl/shaders/mtl/background.hpp +++ b/include/mbgl/shaders/mtl/background.hpp @@ -80,7 +80,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/debug.hpp b/include/mbgl/shaders/mtl/debug.hpp index 5300da6ef0d..633c6a0a985 100644 --- a/include/mbgl/shaders/mtl/debug.hpp +++ b/include/mbgl/shaders/mtl/debug.hpp @@ -34,7 +34,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/fill.hpp b/include/mbgl/shaders/mtl/fill.hpp index a46a2907066..b589a8dca4d 100644 --- a/include/mbgl/shaders/mtl/fill.hpp +++ b/include/mbgl/shaders/mtl/fill.hpp @@ -147,7 +147,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -439,7 +439,7 @@ struct ShaderSource attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/fill_extrusion.hpp b/include/mbgl/shaders/mtl/fill_extrusion.hpp index 440df5ba361..c6540fabed7 100644 --- a/include/mbgl/shaders/mtl/fill_extrusion.hpp +++ b/include/mbgl/shaders/mtl/fill_extrusion.hpp @@ -189,7 +189,7 @@ struct ShaderSource attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/hillshade_prepare.hpp b/include/mbgl/shaders/mtl/hillshade_prepare.hpp index 450399b85a6..8b3770b4d61 100644 --- a/include/mbgl/shaders/mtl/hillshade_prepare.hpp +++ b/include/mbgl/shaders/mtl/hillshade_prepare.hpp @@ -39,7 +39,7 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/line.hpp b/include/mbgl/shaders/mtl/line.hpp index f9656143ff0..b95c3d0c666 100644 --- a/include/mbgl/shaders/mtl/line.hpp +++ b/include/mbgl/shaders/mtl/line.hpp @@ -757,7 +757,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/mtl/symbol.hpp b/include/mbgl/shaders/mtl/symbol.hpp index 496b3239a7a..e3e9bcf9158 100644 --- a/include/mbgl/shaders/mtl/symbol.hpp +++ b/include/mbgl/shaders/mtl/symbol.hpp @@ -79,7 +79,7 @@ struct ShaderSource { static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -422,7 +422,7 @@ struct ShaderSource static constexpr auto vertexMainFunction = "vertexMain"; static constexpr auto fragmentMainFunction = "fragmentMain"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/vulkan/background.hpp b/include/mbgl/shaders/vulkan/background.hpp index ec9b6ef0284..a1946e249a5 100644 --- a/include/mbgl/shaders/vulkan/background.hpp +++ b/include/mbgl/shaders/vulkan/background.hpp @@ -63,7 +63,7 @@ template <> struct ShaderSource { static constexpr const char* name = "BackgroundPatternShader"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/vulkan/circle.hpp b/include/mbgl/shaders/vulkan/circle.hpp index b96c2689273..a68a38e89a9 100644 --- a/include/mbgl/shaders/vulkan/circle.hpp +++ b/include/mbgl/shaders/vulkan/circle.hpp @@ -18,7 +18,7 @@ template <> struct ShaderSource { static constexpr const char* name = "CircleShader"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp b/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp index ce0e3763877..f294035d436 100644 --- a/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/vulkan/custom_symbol_icon.hpp @@ -17,7 +17,7 @@ template <> struct ShaderSource { static constexpr const char* name = "CustomSymbolIconShader"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/vulkan/fill.hpp b/include/mbgl/shaders/vulkan/fill.hpp index 4920915449a..63cca0cf192 100644 --- a/include/mbgl/shaders/vulkan/fill.hpp +++ b/include/mbgl/shaders/vulkan/fill.hpp @@ -111,7 +111,7 @@ template <> struct ShaderSource { static constexpr const char* name = "FillOutlineShader"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; @@ -216,7 +216,7 @@ template <> struct ShaderSource { static constexpr const char* name = "FillPatternShader"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/vulkan/fill_extrusion.hpp b/include/mbgl/shaders/vulkan/fill_extrusion.hpp index c4f82e32392..6ad1da24fd3 100644 --- a/include/mbgl/shaders/vulkan/fill_extrusion.hpp +++ b/include/mbgl/shaders/vulkan/fill_extrusion.hpp @@ -19,7 +19,7 @@ template <> struct ShaderSource { static constexpr const char* name = "FillExtrusionShader"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/vulkan/line.hpp b/include/mbgl/shaders/vulkan/line.hpp index f47893a0f45..4dc3cdbd601 100644 --- a/include/mbgl/shaders/vulkan/line.hpp +++ b/include/mbgl/shaders/vulkan/line.hpp @@ -755,7 +755,7 @@ template <> struct ShaderSource { static constexpr const char* name = "LineSDFShader"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/shaders/vulkan/symbol.hpp b/include/mbgl/shaders/vulkan/symbol.hpp index c183b500530..dfca8285b51 100644 --- a/include/mbgl/shaders/vulkan/symbol.hpp +++ b/include/mbgl/shaders/vulkan/symbol.hpp @@ -188,7 +188,7 @@ template <> struct ShaderSource { static constexpr const char* name = "SymbolSDFIconShader"; - static const std::array attributes; + static const std::array attributes; static constexpr std::array instanceAttributes{}; static const std::array textures; diff --git a/include/mbgl/vulkan/uniform_buffer.hpp b/include/mbgl/vulkan/uniform_buffer.hpp index 68305401bce..83854bee3a2 100644 --- a/include/mbgl/vulkan/uniform_buffer.hpp +++ b/include/mbgl/vulkan/uniform_buffer.hpp @@ -53,11 +53,8 @@ class UniformBufferArray final : public gfx::UniformBufferArray { const std::shared_ptr& set(const size_t id, std::shared_ptr uniformBuffer) override; - void createOrUpdate(const size_t id, - const void* data, - std::size_t size, - gfx::Context& context, - bool persistent = false) override; + void createOrUpdate( + const size_t id, const void* data, std::size_t size, gfx::Context& context, bool persistent = false) override; void bindDescriptorSets(CommandEncoder& encoder); void freeDescriptorSets() { descriptorSet.reset(); } diff --git a/src/mbgl/gfx/uniform_buffer.cpp b/src/mbgl/gfx/uniform_buffer.cpp index bf4edd7f6d6..5f357b99944 100644 --- a/src/mbgl/gfx/uniform_buffer.cpp +++ b/src/mbgl/gfx/uniform_buffer.cpp @@ -36,16 +36,15 @@ const std::shared_ptr& UniformBufferArray::set(const size_t id, return uniformBufferVector[id]; } -void UniformBufferArray::createOrUpdate( - const size_t id, const std::vector& data, gfx::Context& context, bool persistent) { - createOrUpdate(id, data.data(), data.size(), context, persistent); -} - void UniformBufferArray::createOrUpdate(const size_t id, - const void* data, - const std::size_t size, + const std::vector& data, gfx::Context& context, bool persistent) { + createOrUpdate(id, data.data(), data.size(), context, persistent); +} + +void UniformBufferArray::createOrUpdate( + const size_t id, const void* data, const std::size_t size, gfx::Context& context, bool persistent) { if (auto& ubo = get(id); ubo && ubo->getSize() == size) { ubo->update(data, size); } else { diff --git a/src/mbgl/shaders/gl/shader_info.cpp b/src/mbgl/shaders/gl/shader_info.cpp index e017a8ce117..c51b8da8b0e 100644 --- a/src/mbgl/shaders/gl/shader_info.cpp +++ b/src/mbgl/shaders/gl/shader_info.cpp @@ -18,7 +18,7 @@ TextureInfo::TextureInfo(std::string_view name_, std::size_t id_) id(id_) {} // Background -using BackgroundShaderInfo= ShaderInfo; +using BackgroundShaderInfo = ShaderInfo; const std::vector BackgroundShaderInfo::uniformBlocks = { UniformBlockInfo{"BackgroundDrawableUBO", idBackgroundDrawableUBO}, @@ -33,12 +33,12 @@ const std::vector BackgroundShaderInfo::textures = {}; using BackgroundPatternShaderInfo = ShaderInfo; const std::vector BackgroundPatternShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"BackgroundPatternDrawableUBO", idBackgroundDrawableUBO}, - UniformBlockInfo{"BackgroundPatternPropsUBO", idBackgroundPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"BackgroundPatternDrawableUBO", idBackgroundDrawableUBO}, + UniformBlockInfo{"BackgroundPatternPropsUBO", idBackgroundPropsUBO}, }; const std::vector BackgroundPatternShaderInfo::attributes = { - AttributeInfo{"a_pos", idBackgroundPosVertexAttribute}, + AttributeInfo{"a_pos", idBackgroundPosVertexAttribute}, }; const std::vector BackgroundPatternShaderInfo::textures = { TextureInfo{"u_image", idBackgroundImageTexture}, @@ -68,8 +68,8 @@ const std::vector CircleShaderInfo::textures = {}; using CollisionBoxShaderInfo = ShaderInfo; const std::vector CollisionBoxShaderInfo::uniformBlocks = { - UniformBlockInfo{"CollisionDrawableUBO", idCollisionDrawableUBO}, - UniformBlockInfo{"CollisionTilePropsUBO", idCollisionTilePropsUBO}, + UniformBlockInfo{"CollisionDrawableUBO", idCollisionDrawableUBO}, + UniformBlockInfo{"CollisionTilePropsUBO", idCollisionTilePropsUBO}, }; const std::vector CollisionBoxShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, @@ -84,8 +84,8 @@ const std::vector CollisionBoxShaderInfo::textures = {}; using CollisionCircleShaderInfo = ShaderInfo; const std::vector CollisionCircleShaderInfo::uniformBlocks = { - UniformBlockInfo{"CollisionDrawableUBO", idCollisionDrawableUBO}, - UniformBlockInfo{"CollisionTilePropsUBO", idCollisionTilePropsUBO}, + UniformBlockInfo{"CollisionDrawableUBO", idCollisionDrawableUBO}, + UniformBlockInfo{"CollisionTilePropsUBO", idCollisionTilePropsUBO}, }; const std::vector CollisionCircleShaderInfo::attributes = { AttributeInfo{"a_pos", idCollisionPosVertexAttribute}, @@ -99,7 +99,7 @@ const std::vector CollisionCircleShaderInfo::textures = {}; using CustomSymbolIconShaderInfo = ShaderInfo; const std::vector CustomSymbolIconShaderInfo::uniformBlocks = { - UniformBlockInfo{"CustomSymbolIconDrawableUBO", idCustomSymbolDrawableUBO}, + UniformBlockInfo{"CustomSymbolIconDrawableUBO", idCustomSymbolDrawableUBO}, }; const std::vector CustomSymbolIconShaderInfo::attributes = { AttributeInfo{"a_pos", idCustomSymbolPosVertexAttribute}, @@ -140,9 +140,9 @@ const std::vector FillShaderInfo::textures = {}; using FillOutlineShaderInfo = ShaderInfo; const std::vector FillOutlineShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"FillOutlineDrawableUBO", idFillDrawableUBO}, - UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"FillOutlineDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; const std::vector FillOutlineShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, @@ -155,10 +155,10 @@ const std::vector FillOutlineShaderInfo::textures = {}; using FillPatternShaderInfo = ShaderInfo; const std::vector FillPatternShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"FillPatternDrawableUBO", idFillDrawableUBO}, - UniformBlockInfo{"FillPatternTilePropsUBO", idFillTilePropsUBO}, - UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"FillPatternDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillPatternTilePropsUBO", idFillTilePropsUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; const std::vector FillPatternShaderInfo::attributes = { AttributeInfo{"a_pos", idFillPosVertexAttribute}, @@ -174,32 +174,33 @@ const std::vector FillPatternShaderInfo::textures = { using FillOutlinePatternShaderInfo = ShaderInfo; const std::vector FillOutlinePatternShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillDrawableUBO}, - UniformBlockInfo{"FillOutlinePatternTilePropsUBO", idFillTilePropsUBO}, - UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"FillOutlinePatternDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillOutlinePatternTilePropsUBO", idFillTilePropsUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; const std::vector FillOutlinePatternShaderInfo::attributes = { - AttributeInfo{"a_pos", idFillPosVertexAttribute}, - AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, - AttributeInfo{"a_pattern_from", idFillPatternFromVertexAttribute}, - AttributeInfo{"a_pattern_to", idFillPatternToVertexAttribute}, + AttributeInfo{"a_pos", idFillPosVertexAttribute}, + AttributeInfo{"a_opacity", idFillOpacityVertexAttribute}, + AttributeInfo{"a_pattern_from", idFillPatternFromVertexAttribute}, + AttributeInfo{"a_pattern_to", idFillPatternToVertexAttribute}, }; const std::vector FillOutlinePatternShaderInfo::textures = { TextureInfo{"u_image", idFillImageTexture}, }; // Fill Outline Triangulated -using FillOutlineTriangulatedShaderInfo = ShaderInfo; +using FillOutlineTriangulatedShaderInfo = + ShaderInfo; const std::vector FillOutlineTriangulatedShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"FillOutlineTriangulatedDrawableUBO", idFillDrawableUBO}, - UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"FillOutlineTriangulatedDrawableUBO", idFillDrawableUBO}, + UniformBlockInfo{"FillEvaluatedPropsUBO", idFillEvaluatedPropsUBO}, }; const std::vector FillOutlineTriangulatedShaderInfo::attributes = { - AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, - AttributeInfo{"a_data", idLineDataVertexAttribute}, + AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, + AttributeInfo{"a_data", idLineDataVertexAttribute}, }; const std::vector FillOutlineTriangulatedShaderInfo::textures = {}; @@ -207,9 +208,9 @@ const std::vector FillOutlineTriangulatedShaderInfo::textures = {}; using FillExtrusionShaderInfo = ShaderInfo; const std::vector FillExtrusionShaderInfo::uniformBlocks = { - UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, - UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, - UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, + UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, + UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, + UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, }; const std::vector FillExtrusionShaderInfo::attributes = { AttributeInfo{"a_pos", idFillExtrusionPosVertexAttribute}, @@ -224,18 +225,18 @@ const std::vector FillExtrusionShaderInfo::textures = {}; using FillExtrusionPatternShaderInfo = ShaderInfo; const std::vector FillExtrusionPatternShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, - UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, - UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"FillExtrusionDrawableUBO", idFillExtrusionDrawableUBO}, + UniformBlockInfo{"FillExtrusionTilePropsUBO", idFillExtrusionTilePropsUBO}, + UniformBlockInfo{"FillExtrusionPropsUBO", idFillExtrusionPropsUBO}, }; const std::vector FillExtrusionPatternShaderInfo::attributes = { - AttributeInfo{"a_pos", idFillExtrusionPosVertexAttribute}, - AttributeInfo{"a_normal_ed", idFillExtrusionNormalEdVertexAttribute}, - AttributeInfo{"a_base", idFillExtrusionBaseVertexAttribute}, - AttributeInfo{"a_height", idFillExtrusionHeightVertexAttribute}, - AttributeInfo{"a_pattern_from", idFillExtrusionPatternFromVertexAttribute}, - AttributeInfo{"a_pattern_to", idFillExtrusionPatternToVertexAttribute}, + AttributeInfo{"a_pos", idFillExtrusionPosVertexAttribute}, + AttributeInfo{"a_normal_ed", idFillExtrusionNormalEdVertexAttribute}, + AttributeInfo{"a_base", idFillExtrusionBaseVertexAttribute}, + AttributeInfo{"a_height", idFillExtrusionHeightVertexAttribute}, + AttributeInfo{"a_pattern_from", idFillExtrusionPatternFromVertexAttribute}, + AttributeInfo{"a_pattern_to", idFillExtrusionPatternToVertexAttribute}, }; const std::vector FillExtrusionPatternShaderInfo::textures = { TextureInfo{"u_image", idFillExtrusionImageTexture}, @@ -259,8 +260,8 @@ const std::vector HeatmapShaderInfo::textures = {}; using HeatmapTextureShaderInfo = ShaderInfo; const std::vector HeatmapTextureShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"HeatmapTexturePropsUBO", idHeatmapTexturePropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"HeatmapTexturePropsUBO", idHeatmapTexturePropsUBO}, }; const std::vector HeatmapTextureShaderInfo::attributes = { AttributeInfo{"a_pos", idHeatmapPosVertexAttribute}, @@ -274,8 +275,8 @@ const std::vector HeatmapTextureShaderInfo::textures = { using HillshadePrepareShaderInfo = ShaderInfo; const std::vector HillshadePrepareShaderInfo::uniformBlocks = { - UniformBlockInfo{"HillshadePrepareDrawableUBO", idHillshadePrepareDrawableUBO}, - UniformBlockInfo{"HillshadePrepareTilePropsUBO", idHillshadePrepareTilePropsUBO}, + UniformBlockInfo{"HillshadePrepareDrawableUBO", idHillshadePrepareDrawableUBO}, + UniformBlockInfo{"HillshadePrepareTilePropsUBO", idHillshadePrepareTilePropsUBO}, }; const std::vector HillshadePrepareShaderInfo::attributes = { AttributeInfo{"a_pos", idHillshadePosVertexAttribute}, @@ -325,9 +326,9 @@ const std::vector LineShaderInfo::textures = {}; using LineGradientShaderInfo = ShaderInfo; const std::vector LineGradientShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"LineGradientDrawableUBO", idLineDrawableUBO}, - UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"LineGradientDrawableUBO", idLineDrawableUBO}, + UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, }; const std::vector LineGradientShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, @@ -346,10 +347,10 @@ const std::vector LineGradientShaderInfo::textures = { using LinePatternShaderInfo = ShaderInfo; const std::vector LinePatternShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"LinePatternDrawableUBO", idLineDrawableUBO}, - UniformBlockInfo{"LinePatternTilePropsUBO", idLineTilePropsUBO}, - UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"LinePatternDrawableUBO", idLineDrawableUBO}, + UniformBlockInfo{"LinePatternTilePropsUBO", idLineTilePropsUBO}, + UniformBlockInfo{"LineEvaluatedPropsUBO", idLineEvaluatedPropsUBO}, }; const std::vector LinePatternShaderInfo::attributes = { AttributeInfo{"a_pos_normal", idLinePosNormalVertexAttribute}, @@ -431,10 +432,10 @@ const std::vector SymbolIconShaderInfo::textures = { using SymbolSDFIconShaderInfo = ShaderInfo; const std::vector SymbolSDFIconShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, - UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, - UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, + UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, + UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, }; const std::vector SymbolSDFIconShaderInfo::attributes = { AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, @@ -456,21 +457,21 @@ const std::vector SymbolSDFIconShaderInfo::textures = { using SymbolTextAndIconShaderInfo = ShaderInfo; const std::vector SymbolTextAndIconShaderInfo::uniformBlocks = { - UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, - UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, - UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, - UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, + UniformBlockInfo{"GlobalPaintParamsUBO", idGlobalPaintParamsUBO}, + UniformBlockInfo{"SymbolDrawableUBO", idSymbolDrawableUBO}, + UniformBlockInfo{"SymbolTilePropsUBO", idSymbolTilePropsUBO}, + UniformBlockInfo{"SymbolEvaluatedPropsUBO", idSymbolEvaluatedPropsUBO}, }; const std::vector SymbolTextAndIconShaderInfo::attributes = { - AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, - AttributeInfo{"a_data", idSymbolDataVertexAttribute}, - AttributeInfo{"a_projected_pos", idSymbolProjectedPosVertexAttribute}, - AttributeInfo{"a_fade_opacity", idSymbolFadeOpacityVertexAttribute}, - AttributeInfo{"a_fill_color", idSymbolColorVertexAttribute}, - AttributeInfo{"a_halo_color", idSymbolHaloColorVertexAttribute}, - AttributeInfo{"a_opacity", idSymbolOpacityVertexAttribute}, - AttributeInfo{"a_halo_width", idSymbolHaloWidthVertexAttribute}, - AttributeInfo{"a_halo_blur", idSymbolHaloBlurVertexAttribute}, + AttributeInfo{"a_pos_offset", idSymbolPosOffsetVertexAttribute}, + AttributeInfo{"a_data", idSymbolDataVertexAttribute}, + AttributeInfo{"a_projected_pos", idSymbolProjectedPosVertexAttribute}, + AttributeInfo{"a_fade_opacity", idSymbolFadeOpacityVertexAttribute}, + AttributeInfo{"a_fill_color", idSymbolColorVertexAttribute}, + AttributeInfo{"a_halo_color", idSymbolHaloColorVertexAttribute}, + AttributeInfo{"a_opacity", idSymbolOpacityVertexAttribute}, + AttributeInfo{"a_halo_width", idSymbolHaloWidthVertexAttribute}, + AttributeInfo{"a_halo_blur", idSymbolHaloBlurVertexAttribute}, }; const std::vector SymbolTextAndIconShaderInfo::textures = { TextureInfo{"u_texture", idSymbolImageTexture}, diff --git a/src/mbgl/vulkan/context.cpp b/src/mbgl/vulkan/context.cpp index daa98ce7e51..cdedf8b0913 100644 --- a/src/mbgl/vulkan/context.cpp +++ b/src/mbgl/vulkan/context.cpp @@ -114,10 +114,14 @@ void Context::initFrameResources() { buildUniformDescriptorSetLayout( globalUniformDescriptorSetLayout, 0, shaders::globalUBOCount, "GlobalUniformDescriptorSetLayout"); - buildUniformDescriptorSetLayout( - layerUniformDescriptorSetLayout, shaders::layerUBOStartId, shaders::maxUBOCountPerLayer, "LayerUniformDescriptorSetLayout"); - buildUniformDescriptorSetLayout( - drawableUniformDescriptorSetLayout, shaders::globalUBOCount, shaders::maxUBOCountPerDrawable, "DrawableUniformDescriptorSetLayout"); + buildUniformDescriptorSetLayout(layerUniformDescriptorSetLayout, + shaders::layerUBOStartId, + shaders::maxUBOCountPerLayer, + "LayerUniformDescriptorSetLayout"); + buildUniformDescriptorSetLayout(drawableUniformDescriptorSetLayout, + shaders::globalUBOCount, + shaders::maxUBOCountPerDrawable, + "DrawableUniformDescriptorSetLayout"); buildImageDescriptorSetLayout(); } @@ -445,7 +449,8 @@ void Context::bindGlobalUniformBuffers(gfx::RenderPass& renderPass) const noexce const shaders::GlobalPlatformParamsUBO platformUBO = { /* .rotation0 = */ {cosf(surfaceRotation), -sinf(surfaceRotation)}, /* .rotation1 = */ {sinf(surfaceRotation), cosf(surfaceRotation)}}; - context.globalUniformBuffers.createOrUpdate(shaders::idGlobalPlatformParamsUBO, &platformUBO, sizeof(platformUBO), context); + context.globalUniformBuffers.createOrUpdate( + shaders::idGlobalPlatformParamsUBO, &platformUBO, sizeof(platformUBO), context); } context.globalUniformBuffers.bindDescriptorSets(renderPassImpl.getEncoder()); From 0fe9fee1adee297fcd6860384ee6c4eccb0bd8c8 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Sun, 15 Dec 2024 22:52:26 +0200 Subject: [PATCH 10/13] Vulkan. --- include/mbgl/gfx/context.hpp | 2 +- include/mbgl/mtl/context.hpp | 2 +- include/mbgl/shaders/layer_ubo.hpp | 2 +- .../mbgl/shaders/mtl/custom_symbol_icon.hpp | 2 +- include/mbgl/shaders/shader_defines.hpp | 2 + include/mbgl/shaders/vulkan/background.hpp | 29 +++- include/mbgl/shaders/vulkan/circle.hpp | 13 +- include/mbgl/shaders/vulkan/common.hpp | 4 +- include/mbgl/shaders/vulkan/fill.hpp | 117 +++++++++++-- .../mbgl/shaders/vulkan/fill_extrusion.hpp | 40 ++++- include/mbgl/shaders/vulkan/heatmap.hpp | 13 +- include/mbgl/shaders/vulkan/hillshade.hpp | 27 ++- include/mbgl/shaders/vulkan/line.hpp | 89 ++++++++-- .../shaders/vulkan/location_indicator.hpp | 2 +- include/mbgl/shaders/vulkan/raster.hpp | 13 +- include/mbgl/shaders/vulkan/symbol.hpp | 84 +++++++-- include/mbgl/vulkan/context.hpp | 7 +- include/mbgl/vulkan/descriptor_set.hpp | 16 +- include/mbgl/vulkan/uniform_buffer.hpp | 9 +- src/mbgl/gl/context.cpp | 2 +- src/mbgl/gl/context.hpp | 2 +- src/mbgl/mtl/context.cpp | 2 +- .../layers/background_layer_tweaker.cpp | 4 +- .../renderer/layers/circle_layer_tweaker.cpp | 2 +- .../layers/fill_extrusion_layer_tweaker.cpp | 4 +- .../renderer/layers/fill_layer_tweaker.cpp | 7 +- .../renderer/layers/heatmap_layer_tweaker.cpp | 4 +- .../layers/hillshade_layer_tweaker.cpp | 4 +- .../renderer/layers/line_layer_tweaker.cpp | 6 +- .../renderer/layers/raster_layer_tweaker.cpp | 2 +- .../renderer/layers/symbol_layer_tweaker.cpp | 4 +- src/mbgl/renderer/renderer_impl.cpp | 20 ++- .../renderer/sources/render_tile_source.cpp | 163 +++++++++--------- .../style/layers/custom_drawable_layer.cpp | 88 ++++++---- src/mbgl/vulkan/buffer_resource.cpp | 4 +- src/mbgl/vulkan/context.cpp | 50 ++++-- src/mbgl/vulkan/descriptor_set.cpp | 34 ++-- src/mbgl/vulkan/drawable.cpp | 7 + src/mbgl/vulkan/drawable_impl.hpp | 2 +- src/mbgl/vulkan/layer_group.cpp | 2 +- src/mbgl/vulkan/tile_layer_group.cpp | 2 +- src/mbgl/vulkan/uniform_buffer.cpp | 8 +- 42 files changed, 636 insertions(+), 260 deletions(-) diff --git a/include/mbgl/gfx/context.hpp b/include/mbgl/gfx/context.hpp index 8e21265098f..921374d4281 100644 --- a/include/mbgl/gfx/context.hpp +++ b/include/mbgl/gfx/context.hpp @@ -125,7 +125,7 @@ class Context { /// @param data The data to copy, may be `nullptr` /// @param size The size of the buffer /// @param persistent Performance hint, optimize for few or many uses - virtual UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false) = 0; + virtual UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false, bool ssbo = false) = 0; /// Get the generic shader with the specified name virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0; diff --git a/include/mbgl/mtl/context.hpp b/include/mbgl/mtl/context.hpp index 6934ced790f..a6349faf942 100644 --- a/include/mbgl/mtl/context.hpp +++ b/include/mbgl/mtl/context.hpp @@ -83,7 +83,7 @@ class Context final : public gfx::Context { void reduceMemoryUsage() override {} gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override; - gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persisten) override; + gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false, bool ssbo = false) override; gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override; diff --git a/include/mbgl/shaders/layer_ubo.hpp b/include/mbgl/shaders/layer_ubo.hpp index fd9b91a3e05..1f3d97887c0 100644 --- a/include/mbgl/shaders/layer_ubo.hpp +++ b/include/mbgl/shaders/layer_ubo.hpp @@ -75,7 +75,7 @@ enum { drawableReservedUBOCount }; -#define MLN_UBO_CONSOLIDATION MLN_RENDER_BACKEND_METAL +#define MLN_UBO_CONSOLIDATION (MLN_RENDER_BACKEND_METAL || MLN_RENDER_BACKEND_VULKAN) } // namespace shaders } // namespace mbgl diff --git a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp index a52674c5e1b..82581e74d37 100644 --- a/include/mbgl/shaders/mtl/custom_symbol_icon.hpp +++ b/include/mbgl/shaders/mtl/custom_symbol_icon.hpp @@ -29,7 +29,7 @@ struct alignas(16) CustomSymbolIconDrawableUBO { /* 108 */ float pad3; /* 112 */ }; -static_assert(sizeof(CustomSymbolIconParametersUBO) == 7 * 16, "wrong size"); +static_assert(sizeof(CustomSymbolIconDrawableUBO) == 7 * 16, "wrong size"); )" diff --git a/include/mbgl/shaders/shader_defines.hpp b/include/mbgl/shaders/shader_defines.hpp index 692c688a188..557921146e2 100644 --- a/include/mbgl/shaders/shader_defines.hpp +++ b/include/mbgl/shaders/shader_defines.hpp @@ -101,6 +101,7 @@ enum { wideVectorDrawableUBOCount }; +static constexpr auto layerSSBOStartId = globalUBOCount; static constexpr auto layerUBOStartId = std::max({static_cast(backgroundDrawableUBOCount), static_cast(circleDrawableUBOCount), static_cast(clippingMaskDrawableUBOCount), @@ -228,6 +229,7 @@ static constexpr auto maxUBOCountPerShader = std::max({static_cast(backg static_cast(symbolUBOCount), static_cast(wideVectorUBOCount)}); +static constexpr auto maxSSBOCountPerLayer = maxUBOCountPerDrawable; static constexpr auto maxUBOCountPerLayer = maxUBOCountPerShader - layerUBOStartId; // Texture defines diff --git a/include/mbgl/shaders/vulkan/background.hpp b/include/mbgl/shaders/vulkan/background.hpp index a1946e249a5..2fa7df3478d 100644 --- a/include/mbgl/shaders/vulkan/background.hpp +++ b/include/mbgl/shaders/vulkan/background.hpp @@ -26,11 +26,23 @@ struct ShaderSource { layout(location = 0) in ivec2 in_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idBackgroundDrawableUBO) uniform BackgroundDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct BackgroundDrawableUBO { mat4 matrix; -} drawable; + vec4 pad1; + vec4 pad2; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idBackgroundDrawableUBO) readonly buffer BackgroundDrawableUBOVector { + BackgroundDrawableUBO drawable_ubo[]; +} drawableVector; void main() { + const BackgroundDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; + gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0); applySurfaceTransform(); } @@ -70,7 +82,11 @@ struct ShaderSource { layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec2 in_texture_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idHillshadeDrawableUBO) uniform HillshadeDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct HillshadeDrawableUBO { mat4 matrix; -} drawable; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idHillshadeDrawableUBO) readonly buffer HillshadeDrawableUBOVector { + HillshadeDrawableUBO drawable_ubo[]; +} drawableVector; layout(location = 0) out vec2 frag_position; void main() { + const HillshadeDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; gl_Position = drawable.matrix * vec4(in_position, 0.0, 1.0); applySurfaceTransform(); @@ -49,10 +58,18 @@ void main() { layout(location = 0) in vec2 frag_position; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idHillshadeTilePropsUBO) uniform HillshadeTilePropsUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct HillshadeTilePropsUBO { vec2 latrange; vec2 light; -} tileProps; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idHillshadeTilePropsUBO) readonly buffer HillshadeTilePropsUBOVector { + HillshadeTilePropsUBO tile_props_ubo[]; +} tilePropsVector; layout(set = LAYER_SET_INDEX, binding = idHillshadeEvaluatedPropsUBO) uniform HillshadeEvaluatedPropsUBO { vec4 highlight; @@ -69,6 +86,8 @@ void main() { return; #endif + const HillshadeTilePropsUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index]; + vec4 pixel = texture(image_sampler, frag_position); vec2 deriv = pixel.rg * 2.0 - 1.0; diff --git a/include/mbgl/shaders/vulkan/line.hpp b/include/mbgl/shaders/vulkan/line.hpp index 4dc3cdbd601..20fd60d2fdd 100644 --- a/include/mbgl/shaders/vulkan/line.hpp +++ b/include/mbgl/shaders/vulkan/line.hpp @@ -52,7 +52,11 @@ layout(location = 6) in vec2 in_offset; layout(location = 7) in vec2 in_width; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct LineDrawableUBO { mat4 matrix; mediump float ratio; // Interpolations @@ -63,7 +67,13 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineDr float offset_t; float width_t; float pad1; -} drawable; + vec4 pad2; + vec4 pad3; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idLineDrawableUBO) readonly buffer LineDrawableUBOVector { + LineDrawableUBO drawable_ubo[]; +} drawableVector; layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; @@ -94,6 +104,7 @@ layout(location = 5) out lowp float frag_opacity; #endif void main() { + const LineDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; #ifndef HAS_UNIFORM_u_color frag_color = unpack_mix_color(in_color, drawable.color_t); @@ -275,7 +286,11 @@ layout(location = 5) in vec2 in_offset; layout(location = 6) in vec2 in_width; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineGradientDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct LineGradientDrawableUBO { mat4 matrix; mediump float ratio; // Interpolations @@ -286,7 +301,13 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineGr float width_t; float pad1; float pad2; -} drawable; + vec4 pad3; + vec4 pad4; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idLineDrawableUBO) readonly buffer LineGradientDrawableUBOVector { + LineGradientDrawableUBO drawable_ubo[]; +} drawableVector; layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; @@ -314,6 +335,7 @@ layout(location = 5) out lowp float frag_opacity; #endif void main() { + const LineGradientDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; #ifndef HAS_UNIFORM_u_blur frag_blur = unpack_mix_float(in_blur, drawable.blur_t); @@ -497,7 +519,11 @@ layout(location = 7) in uvec4 in_pattern_from; layout(location = 8) in uvec4 in_pattern_to; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LinePatternDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct LinePatternDrawableUBO { mat4 matrix; float ratio; // Interpolations @@ -508,7 +534,13 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LinePa float width_t; float pattern_from_t; float pattern_to_t; -} drawable; + vec4 pad1; + vec4 pad2; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idLineDrawableUBO) readonly buffer LinePatternDrawableUBOVector { + LinePatternDrawableUBO drawable_ubo[]; +} drawableVector; layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; @@ -544,6 +576,7 @@ layout(location = 7) out mediump vec4 frag_pattern_to; #endif void main() { + const LinePatternDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; #ifndef HAS_UNIFORM_u_blur frag_blur = unpack_mix_float(in_blur, drawable.blur_t); @@ -652,14 +685,22 @@ layout(location = 7) in mediump vec4 frag_pattern_to; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineTilePropsUBO) uniform LinePatternTilePropertiesUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct LinePatternTilePropertiesUBO { vec4 pattern_from; vec4 pattern_to; vec4 scale; vec2 texsize; float fade; float pad1; -} tileProps; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idLineTilePropsUBO) readonly buffer LinePatternTilePropertiesUBOVector { + LinePatternTilePropertiesUBO tile_props_ubo[]; +} tilePropsVector; layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; @@ -682,6 +723,8 @@ void main() { return; #endif + const LinePatternTilePropertiesUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index]; + #ifdef HAS_UNIFORM_u_blur const lowp float blur = props.blur; #else @@ -792,7 +835,11 @@ layout(location = 7) in vec2 in_width; layout(location = 8) in vec2 in_floorwidth; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineSDFDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct LineSDFDrawableUBO { mat4 matrix; vec2 patternscale_a; vec2 patternscale_b; @@ -809,7 +856,11 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineDrawableUBO) uniform LineSD float floorwidth_t; float pad1; float pad2; -} drawable; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idLineDrawableUBO) readonly buffer LineSDFDrawableUBOVector { + LineSDFDrawableUBO drawable_ubo[]; +} drawableVector; layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; @@ -846,6 +897,7 @@ layout(location = 8) out mediump float frag_floorwidth; #endif void main() { + const LineSDFDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; #ifndef HAS_UNIFORM_u_color frag_color = unpack_mix_color(in_color, intdrawableerp.color_t); @@ -961,12 +1013,23 @@ layout(location = 8) in mediump float frag_floorwidth; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idLineTilePropsUBO) uniform LineSDFInterpolationUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct LineSDFTilePropsUBO { float sdfgamma; float mix; float pad1; float pad2; -} tileProps; + vec4 pad3; + vec4 pad4; + vec4 pad5; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idLineTilePropsUBO) readonly buffer LineSDFTilePropsUBOVector { + LineSDFTilePropsUBO tile_props_ubo[]; +} tilePropsVector; layout(set = LAYER_SET_INDEX, binding = idLineEvaluatedPropsUBO) uniform LineEvaluatedPropsUBO { vec4 color; @@ -989,6 +1052,8 @@ void main() { return; #endif + const LineSDFTilePropsUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index]; + #ifdef HAS_UNIFORM_u_color const lowp vec4 color = props.color; #else diff --git a/include/mbgl/shaders/vulkan/location_indicator.hpp b/include/mbgl/shaders/vulkan/location_indicator.hpp index 5a06107e559..a1181fdc9b2 100644 --- a/include/mbgl/shaders/vulkan/location_indicator.hpp +++ b/include/mbgl/shaders/vulkan/location_indicator.hpp @@ -57,7 +57,7 @@ struct ShaderSource instanceAttributes{}; static const std::array textures; - static constexpr auto vertex = R"( + static constexpr auto vertex = LOCATION_INDICATOR_SHADER_PRELUDE R"( layout(location = 0) in vec2 in_position; layout(location = 1) in vec2 in_texcoord; diff --git a/include/mbgl/shaders/vulkan/raster.hpp b/include/mbgl/shaders/vulkan/raster.hpp index cb0b89a1487..6727ec0dc31 100644 --- a/include/mbgl/shaders/vulkan/raster.hpp +++ b/include/mbgl/shaders/vulkan/raster.hpp @@ -27,9 +27,17 @@ struct ShaderSource { layout(location = 0) in ivec2 in_position; layout(location = 1) in ivec2 in_texture_position; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idRasterDrawableUBO) uniform RasterDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct RasterDrawableUBO { mat4 matrix; -} drawable; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idRasterDrawableUBO) readonly buffer RasterDrawableUBOVector { + RasterDrawableUBO drawable_ubo[]; +} drawableVector; layout(set = LAYER_SET_INDEX, binding = idRasterEvaluatedPropsUBO) uniform RasterEvaluatedPropsUBO { vec4 spin_weights; @@ -50,6 +58,7 @@ layout(location = 0) out vec2 frag_position0; layout(location = 1) out vec2 frag_position1; void main() { + const RasterDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; gl_Position = drawable.matrix * vec4(in_position, 0, 1); applySurfaceTransform(); diff --git a/include/mbgl/shaders/vulkan/symbol.hpp b/include/mbgl/shaders/vulkan/symbol.hpp index dfca8285b51..c41550bcf34 100644 --- a/include/mbgl/shaders/vulkan/symbol.hpp +++ b/include/mbgl/shaders/vulkan/symbol.hpp @@ -35,7 +35,11 @@ layout(location = 4) in float in_fade_opacity; layout(location = 5) in vec2 in_opacity; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform SymbolDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; @@ -58,13 +62,17 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform Symb float opacity_t; float halo_width_t; float halo_blur_t; - float pad1; -} drawable; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idSymbolDrawableUBO) readonly buffer SymbolDrawableUBOVector { + SymbolDrawableUBO drawable_ubo[]; +} drawableVector; layout(location = 0) out mediump vec2 frag_tex; layout(location = 1) out mediump float frag_opacity; void main() { + const SymbolDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; const vec2 a_pos = in_pos_offset.xy; const vec2 a_offset = in_pos_offset.zw; @@ -143,12 +151,20 @@ layout(location = 1) in mediump float frag_opacity; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolTilePropsUBO) uniform SymbolTilePropsUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct SymbolTilePropsUBO { bool is_text; bool is_halo; float gamma_scale; float pad1; -} tileProps; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idSymbolTilePropsUBO) readonly buffer SymbolTilePropsUBOVector { + SymbolTilePropsUBO tile_props_ubo[]; +} tilePropsVector; layout(set = LAYER_SET_INDEX, binding = idSymbolEvaluatedPropsUBO) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; @@ -173,6 +189,8 @@ void main() { return; #endif + const SymbolTilePropsUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index]; + #if defined(HAS_UNIFORM_u_opacity) const float opacity = (tileProps.is_text ? props.text_opacity : props.icon_opacity) * frag_opacity; #else @@ -220,7 +238,11 @@ layout(location = 8) in vec2 in_halo_width; layout(location = 9) in vec2 in_halo_blur; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform SymbolDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; @@ -243,8 +265,11 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform Symb float opacity_t; float halo_width_t; float halo_blur_t; - float pad1; -} drawable; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idSymbolDrawableUBO) readonly buffer SymbolDrawableUBOVector { + SymbolDrawableUBO drawable_ubo[]; +} drawableVector; layout(location = 0) out mediump vec2 frag_tex; layout(location = 1) out mediump float frag_fade_opacity; @@ -272,6 +297,7 @@ layout(location = 8) out mediump float frag_halo_blur; #endif void main() { + const SymbolDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; const vec2 a_pos = in_pos_offset.xy; const vec2 a_offset = in_pos_offset.zw; @@ -389,12 +415,20 @@ layout(location = 8) in mediump float frag_halo_blur; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolTilePropsUBO) uniform SymbolTilePropsUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct SymbolTilePropsUBO { bool is_text; bool is_halo; float gamma_scale; float pad1; -} tileProps; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idSymbolTilePropsUBO) readonly buffer SymbolTilePropsUBOVector { + SymbolTilePropsUBO tile_props_ubo[]; +} tilePropsVector; layout(set = LAYER_SET_INDEX, binding = idSymbolEvaluatedPropsUBO) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; @@ -420,6 +454,8 @@ void main() { return; #endif + const SymbolTilePropsUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index]; + #if defined(HAS_UNIFORM_u_fill_color) const vec4 fill_color = tileProps.is_text ? props.text_fill_color : props.icon_fill_color; #else @@ -498,7 +534,11 @@ layout(location = 7) in vec2 in_halo_width; layout(location = 8) in vec2 in_halo_blur; #endif -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform SymbolDrawableUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct SymbolDrawableUBO { mat4 matrix; mat4 label_plane_matrix; mat4 coord_matrix; @@ -521,8 +561,11 @@ layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolDrawableUBO) uniform Symb float opacity_t; float halo_width_t; float halo_blur_t; - float pad1; -} drawable; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idSymbolDrawableUBO) readonly buffer SymbolDrawableUBOVector { + SymbolDrawableUBO drawable_ubo[]; +} drawableVector; layout(location = 0) out mediump vec2 frag_tex; layout(location = 1) out mediump float frag_fade_opacity; @@ -552,6 +595,7 @@ layout(location = 8) out mediump float frag_halo_blur; layout(location = 9) out int frag_is_icon; void main() { + const SymbolDrawableUBO drawable = drawableVector.drawable_ubo[constant.ubo_index]; const vec2 a_pos = in_pos_offset.xy; const vec2 a_offset = in_pos_offset.zw; @@ -674,12 +718,20 @@ layout(location = 9) flat in int frag_is_icon; layout(location = 0) out vec4 out_color; -layout(set = DRAWABLE_UBO_SET_INDEX, binding = idSymbolTilePropsUBO) uniform SymbolTilePropsUBO { +layout(push_constant) uniform Constants { + int ubo_index; +} constant; + +struct SymbolTilePropsUBO { bool is_text; bool is_halo; float gamma_scale; float pad1; -} tileProps; +}; + +layout(std140, set = LAYER_SET_INDEX, binding = idSymbolTilePropsUBO) readonly buffer SymbolTilePropsUBOVector { + SymbolTilePropsUBO tile_props_ubo[]; +} tilePropsVector; layout(set = LAYER_SET_INDEX, binding = idSymbolEvaluatedPropsUBO) uniform SymbolEvaluatedPropsUBO { vec4 text_fill_color; @@ -705,6 +757,8 @@ void main() { return; #endif + const SymbolTilePropsUBO tileProps = tilePropsVector.tile_props_ubo[constant.ubo_index]; + #if defined(HAS_UNIFORM_u_fill_color) const vec4 fill_color = tileProps.is_text ? props.text_fill_color : props.icon_fill_color; #else diff --git a/include/mbgl/vulkan/context.hpp b/include/mbgl/vulkan/context.hpp index 3208b3d9dc7..eb6ea156631 100644 --- a/include/mbgl/vulkan/context.hpp +++ b/include/mbgl/vulkan/context.hpp @@ -74,7 +74,7 @@ class Context final : public gfx::Context { void reduceMemoryUsage() override {} gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override; - gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent) override; + gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent, bool ssbo = false) override; gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override; @@ -135,6 +135,7 @@ class Context final : public gfx::Context { const std::unique_ptr& getDummyVertexBuffer(); const std::unique_ptr& getDummyUniformBuffer(); + const std::unique_ptr& getDummyStorageBuffer(); const std::unique_ptr& getDummyTexture(); const vk::DescriptorSetLayout& getDescriptorSetLayout(DescriptorSetType type); @@ -175,7 +176,8 @@ class Context final : public gfx::Context { void buildImageDescriptorSetLayout(); void buildUniformDescriptorSetLayout(vk::UniqueDescriptorSetLayout& layout, - size_t uniformStartId, + size_t startId, + size_t storageCount, size_t uniformCount, const std::string& name); @@ -187,6 +189,7 @@ class Context final : public gfx::Context { std::unique_ptr dummyVertexBuffer; std::unique_ptr dummyUniformBuffer; + std::unique_ptr dummyStorageBuffer; std::unique_ptr dummyTexture2D; vk::UniqueDescriptorSetLayout globalUniformDescriptorSetLayout; vk::UniqueDescriptorSetLayout layerUniformDescriptorSetLayout; diff --git a/include/mbgl/vulkan/descriptor_set.hpp b/include/mbgl/vulkan/descriptor_set.hpp index fff737a7d91..6582216c956 100644 --- a/include/mbgl/vulkan/descriptor_set.hpp +++ b/include/mbgl/vulkan/descriptor_set.hpp @@ -30,7 +30,9 @@ struct DescriptorPoolGrowable { }; const uint32_t maxSets{0}; - const uint32_t descriptorsPerSet{0}; + const uint32_t descriptorStoragePerSet{0}; + const uint32_t descriptorUniformsPerSet{0}; + const uint32_t descriptorTexturesPerSet{0}; const float growFactor{1.5f}; std::vector pools; @@ -39,9 +41,15 @@ struct DescriptorPoolGrowable { PoolInfo& current() { return pools[currentPoolIndex]; } DescriptorPoolGrowable() = default; - DescriptorPoolGrowable(uint32_t maxSets_, uint32_t descriptorsPerSet_, float growFactor_ = 1.5f) + DescriptorPoolGrowable(uint32_t maxSets_, + uint32_t descriptorStoragePerSet_, + uint32_t descriptorUniformsPerSet_, + uint32_t descriptorTexturesPerSet_, + float growFactor_ = 1.5f) : maxSets(maxSets_), - descriptorsPerSet(descriptorsPerSet_), + descriptorStoragePerSet(descriptorStoragePerSet_), + descriptorUniformsPerSet(descriptorUniformsPerSet_), + descriptorTexturesPerSet(descriptorTexturesPerSet_), growFactor(growFactor_) {} }; @@ -72,7 +80,7 @@ class UniformDescriptorSet : public DescriptorSet { UniformDescriptorSet(Context& context_, DescriptorSetType type_); virtual ~UniformDescriptorSet() = default; - void update(const gfx::UniformBufferArray& uniforms, uint32_t uniformStartIndex, uint32_t descriptorBindingCount); + void update(const gfx::UniformBufferArray& uniforms, uint32_t descriptorStartIndex, uint32_t descriptorStorageCount, uint32_t descriptorUniformCount); }; class ImageDescriptorSet : public DescriptorSet { diff --git a/include/mbgl/vulkan/uniform_buffer.hpp b/include/mbgl/vulkan/uniform_buffer.hpp index 83854bee3a2..643f293e955 100644 --- a/include/mbgl/vulkan/uniform_buffer.hpp +++ b/include/mbgl/vulkan/uniform_buffer.hpp @@ -30,10 +30,12 @@ class UniformBufferArray final : public gfx::UniformBufferArray { UniformBufferArray() = delete; UniformBufferArray(DescriptorSetType descriptorSetType_, uint32_t descriptorStartIndex_, - uint32_t descriptorBindingCount_) + uint32_t descriptorStorageCount_, + uint32_t descriptorUniformCount_) : descriptorSetType(descriptorSetType_), descriptorStartIndex(descriptorStartIndex_), - descriptorBindingCount(descriptorBindingCount_) {} + descriptorStorageCount(descriptorStorageCount_), + descriptorUniformCount(descriptorUniformCount_) {} UniformBufferArray(UniformBufferArray&& other) : gfx::UniformBufferArray(std::move(other)) {} @@ -66,7 +68,8 @@ class UniformBufferArray final : public gfx::UniformBufferArray { const DescriptorSetType descriptorSetType{DescriptorSetType::DrawableUniform}; const uint32_t descriptorStartIndex{0}; - const uint32_t descriptorBindingCount{0}; + const uint32_t descriptorStorageCount{0}; + const uint32_t descriptorUniformCount{0}; std::unique_ptr descriptorSet; }; diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 432592612a2..6e95f3df7d5 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -611,7 +611,7 @@ gfx::UniqueDrawableBuilder Context::createDrawableBuilder(std::string name) { return std::make_unique(std::move(name)); } -gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool /*persistent*/) { +gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool /*persistent*/, bool /*ssbo*/) { MLN_TRACE_FUNC(); return std::make_shared(data, size, *uboAllocator); diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index ae3b50cf84b..0b42d58f844 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -120,7 +120,7 @@ class Context final : public gfx::Context { #if MLN_DRAWABLE_RENDERER gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override; - gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent) override; + gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false, bool ssbo = false) override; gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override; diff --git a/src/mbgl/mtl/context.cpp b/src/mbgl/mtl/context.cpp index 675d5c8d120..afa1756b0ad 100644 --- a/src/mbgl/mtl/context.cpp +++ b/src/mbgl/mtl/context.cpp @@ -199,7 +199,7 @@ gfx::UniqueDrawableBuilder Context::createDrawableBuilder(std::string name) { return std::make_unique(std::move(name)); } -gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool persistent) { +gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool persistent, bool /*ssbo*/) { return std::make_shared( createBuffer(data, size, gfx::BufferUsageType::StaticDraw, /*isIndexBuffer=*/false, persistent)); } diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index 769a5818eb7..dbfca5ef36c 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -92,7 +92,9 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, false, false, drawable); +#if !MLN_UBO_CONSOLIDATION auto& drawableUniforms = drawable.mutableUniformBuffers(); +#endif if (hasPattern) { if (const auto& tex = parameters.patternAtlas.texture()) { @@ -146,7 +148,7 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(BackgroundDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index 1a2f461a810..3b3ac5f6f50 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -118,7 +118,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(CircleDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index cf4d8374f1b..044452fabfd 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -155,14 +155,14 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(FillExtrusionDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(FillExtrusionTilePropsUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 5060fd91bc5..8530629f11d 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -101,8 +101,9 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters textureSize = tex->getSize(); } +#if !MLN_UBO_CONSOLIDATION auto& drawableUniforms = drawable.mutableUniformBuffers(); - +#endif switch (static_cast(drawable.getType())) { case RenderFillLayer::FillVariant::Fill: { #if MLN_UBO_CONSOLIDATION @@ -251,14 +252,14 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(FillDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(FillTilePropsUnionUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index 7cbff4afabe..5572a8ba1ac 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -93,12 +93,12 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(HeatmapDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } - layerUniforms.set(idSymbolDrawableUBO, drawableUniformBuffer); + layerUniforms.set(idHeatmapDrawableUBO, drawableUniformBuffer); #endif } diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index ac486d9a00a..db085271f14 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -100,14 +100,14 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam auto& context = parameters.context; const size_t drawableUBOVectorSize = sizeof(HillshadeDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(HillshadeTilePropsUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 87b7b432487..87596e1f7c6 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -187,7 +187,9 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters const auto matrix = getTileMatrix( tileID, parameters, translation, anchor, nearClipped, inViewportPixelUnits, drawable); +#if !MLN_UBO_CONSOLIDATION auto& drawableUniforms = drawable.mutableUniformBuffers(); +#endif switch (static_cast(drawable.getType())) { case LineType::Simple: { #if MLN_UBO_CONSOLIDATION @@ -362,14 +364,14 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(LineDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(LineTilePropsUnionUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index 6b7fb5b1ea1..0303017fc19 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -119,7 +119,7 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, auto& context = parameters.context; const size_t drawableUBOVectorSize = sizeof(RasterDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index 4455fc9626d..e2e7a8ea781 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -203,14 +203,14 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(SymbolDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false); + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(SymbolTilePropsUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false); + tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index ff10be6dd62..bd3631d4af0 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -251,17 +251,20 @@ void Renderer::Impl::render(const RenderTree& renderTree, const auto debugGroup = uploadPass->createDebugGroup("layerGroup-upload"); #endif + // Update the debug layer groups + orchestrator.updateDebugLayerGroups(renderTree, parameters); + // Tweakers are run in the upload pass so they can set up uniforms. parameters.currentLayer = 0; orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.runTweakers(renderTree, parameters); parameters.currentLayer++; }); - orchestrator.visitDebugLayerGroups( - [&](LayerGroupBase& layerGroup) { layerGroup.runTweakers(renderTree, parameters); }); - - // Update the debug layer groups - orchestrator.updateDebugLayerGroups(renderTree, parameters); + parameters.currentLayer = 0; + orchestrator.visitDebugLayerGroups([&](LayerGroupBase& layerGroup) { + layerGroup.runTweakers(renderTree, parameters); + parameters.currentLayer++; + }); // Give the layers a chance to upload orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.upload(*uploadPass); }); @@ -458,8 +461,11 @@ void Renderer::Impl::render(const RenderTree& renderTree, // Renders debug overlays. { const auto debugGroup(parameters.renderPass->createDebugGroup("debug")); - orchestrator.visitDebugLayerGroups( - [&](LayerGroupBase& layerGroup) { layerGroup.render(orchestrator, parameters); }); + parameters.currentLayer = 0; + orchestrator.visitDebugLayerGroups([&](LayerGroupBase& layerGroup) { + layerGroup.render(orchestrator, parameters); + parameters.currentLayer++; + }); } }; #endif // MLN_DRAWABLE_RENDERER diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 82a48a63d92..5a0ebe4b8a1 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -56,7 +56,7 @@ void TileSourceRenderItem::render(PaintParameters& parameters) const { #if MLN_DRAWABLE_RENDERER -#if MLN_RENDER_BACKEND_VULKAN +#if MLN_ENABLE_POLYLINE_DRAWABLES class PolylineLayerImpl : public Layer::Impl { public: PolylineLayerImpl() @@ -88,14 +88,15 @@ class PolylineLayerTweaker : public LayerTweaker { public: PolylineLayerTweaker(const shaders::LineEvaluatedPropsUBO& properties) : LayerTweaker("debug-polyline", makeMutable()), - linePropertiesUBO(properties) {} + propsUBO(properties) {} void execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) override { + auto& context = parameters.context; auto& layerUniforms = layerGroup.mutableUniformBuffers(); - layerUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); + layerUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &propsUBO, context); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty - assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); + assert(propsUBO.expressionMask == LineExpressionMask::None); const LineExpressionUBO exprUBO = { /* .color = */ nullptr, @@ -106,11 +107,66 @@ class PolylineLayerTweaker : public LayerTweaker { /* .width = */ nullptr, /* .floorWidth = */ nullptr, }; - layerUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context); + layerUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, context); + +#if MLN_UBO_CONSOLIDATION + int i = 0; + std::vector drawableUBOVector(layerGroup.getDrawableCount()); +#endif + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { + if (!drawable.getTileID().has_value()) { + return; + } + + const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); + const auto zoom = parameters.state.getZoom(); + mat4 tileMatrix; + parameters.state.matrixFor(/*out*/ tileMatrix, tileID); + + const auto matrix = LayerTweaker::getTileMatrix( + tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); + +#if MLN_UBO_CONSOLIDATION + drawableUBOVector[i].lineDrawableUBO = { +#else + const shaders::LineDrawableUBO drawableUBO = { +#endif + /* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), + + /* .color_t = */ 0.f, + /* .blur_t = */ 0.f, + /* .opacity_t = */ 0.f, + /* .gapwidth_t = */ 0.f, + /* .offset_t = */ 0.f, + /* .width_t = */ 0.f, + /* .pad1 = */ 0}; + +#if MLN_UBO_CONSOLIDATION + drawable.setUBOIndex(i++); +#else + auto& drawableUniforms = drawable.mutableUniformBuffers(); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, context); +#endif + }); + +#if MLN_UBO_CONSOLIDATION + const size_t drawableUBOVectorSize = sizeof(LineDrawableUnionUBO) * drawableUBOVector.size(); + if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { + drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + } else { + drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); + } + layerUniforms.set(idLineDrawableUBO, drawableUniformBuffer); +#endif } private: - shaders::LineEvaluatedPropsUBO linePropertiesUBO; + shaders::LineEvaluatedPropsUBO propsUBO; + +#if MLN_UBO_CONSOLIDATION + gfx::UniformBufferPtr drawableUniformBuffer; +#endif }; #endif @@ -264,64 +320,6 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr // function to add polylines drawable const auto addPolylineDrawable = [&](TileLayerGroup* tileLayerGroup, const RenderTile& tile) { - class PolylineDrawableTweaker : public gfx::DrawableTweaker { - public: - PolylineDrawableTweaker(const shaders::LineEvaluatedPropsUBO& properties) - : linePropertiesUBO(properties) {} - ~PolylineDrawableTweaker() override = default; - - void init(gfx::Drawable&) override {} - - void execute(gfx::Drawable& drawable, const PaintParameters& parameters) override { - if (!drawable.getTileID().has_value()) { - return; - } - - const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); - const auto zoom = parameters.state.getZoom(); - mat4 tileMatrix; - parameters.state.matrixFor(/*out*/ tileMatrix, tileID); - - const auto matrix = LayerTweaker::getTileMatrix( - tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - - const shaders::LineDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(matrix), - /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - - /* .color_t = */ 0.f, - /* .blur_t = */ 0.f, - /* .opacity_t = */ 0.f, - /* .gapwidth_t = */ 0.f, - /* .offset_t = */ 0.f, - /* .width_t = */ 0.f, - /* .pad1 = */ 0}; - auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); - -#if !MLN_RENDER_BACKEND_VULKAN - drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); - - // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty - assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); - - const LineExpressionUBO exprUBO = { - /* .color = */ nullptr, - /* .blur = */ nullptr, - /* .opacity = */ nullptr, - /* .gapwidth = */ nullptr, - /* .offset = */ nullptr, - /* .width = */ nullptr, - /* .floorWidth = */ nullptr, - }; - drawableUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context); -#endif - }; - - private: - shaders::LineEvaluatedPropsUBO linePropertiesUBO; - }; - GeometryCoordinates coords{{0, 0}, {util::EXTENT, 0}, {util::EXTENT, util::EXTENT}, {0, util::EXTENT}, {0, 0}}; gfx::PolylineGeneratorOptions options; options.type = FeatureType::Polygon; @@ -332,24 +330,17 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr } polylineBuilder->addPolyline(coords, options); -#if MLN_RENDER_BACKEND_VULKAN - if (!layerTweaker) { - layerTweaker = std::make_shared(linePropertiesUBO); - layerTweaker->execute(*tileLayerGroup, parameters); - tileLayerGroup->addLayerTweaker(layerTweaker); - } -#endif - - // create line tweaker; - auto tweaker = std::make_shared(linePropertiesUBO); - // finish polylineBuilder->flush(context); for (auto& drawable : polylineBuilder->clearDrawables()) { drawable->setTileID(tile.getOverscaledTileID()); - drawable->addTweaker(tweaker); tileLayerGroup->addDrawable(renderPass, tile.getOverscaledTileID(), std::move(drawable)); } + + if (!layerTweaker) { + layerTweaker = std::make_shared(linePropertiesUBO); + tileLayerGroup->addLayerTweaker(layerTweaker); + } }; #endif @@ -432,16 +423,20 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr const auto& debugBucket = tile.debugBucket; if (!debugBucket) continue; - const DebugUBO debugUBO = {/* .matrix = */ util::cast(tile.matrix), - /* .color = */ Color::red(), - /* .overlay_scale = */ 1.0f, - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0}; - if (0 == updateDrawables(tileLayerGroup, tileID, debugUBO) && tile.getNeedsRendering()) { #if MLN_ENABLE_POLYLINE_DRAWABLES + if (0 == tileLayerGroup->getDrawableCount(renderPass, tileID) && tile.getNeedsRendering()) { addPolylineDrawable(tileLayerGroup, tile); + } #else + const DebugUBO debugUBO = { + /* .matrix = */ util::cast(tile.matrix), + /* .color = */ Color::red(), + /* .overlay_scale = */ 1.0f, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}; + + if (0 == updateDrawables(tileLayerGroup, tileID, debugUBO) && tile.getNeedsRendering()) { addDrawable(tileLayerGroup, tileID, debugUBO, @@ -449,8 +444,8 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr vertices, indexes, segments); -#endif } +#endif } } else { // if tile borders are not required, erase layer group diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index 351258aa618..45477520a95 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -90,7 +90,7 @@ const LayerTypeInfo* CustomDrawableLayer::Impl::staticTypeInfo() noexcept { class LineDrawableTweaker : public gfx::DrawableTweaker { public: LineDrawableTweaker(const shaders::LineEvaluatedPropsUBO& properties) - : linePropertiesUBO(properties) {} + : propsUBO(properties) {} ~LineDrawableTweaker() override = default; void init(gfx::Drawable&) override {} @@ -108,26 +108,44 @@ class LineDrawableTweaker : public gfx::DrawableTweaker { const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::LineDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix), - /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - - /* .color_t = */ 0.f, - /* .blur_t = */ 0.f, - /* .opacity_t = */ 0.f, - /* .gapwidth_t = */ 0.f, - /* .offset_t = */ 0.f, - /* .width_t = */ 0.f, - /* .pad1 = */ 0}; +#if MLN_UBO_CONSOLIDATION + shaders::LineDrawableUnionUBO drawableUBO; + drawableUBO.lineDrawableUBO = { +#else + const shaders::LineDrawableUBO drawableUBO = { +#endif + /* .matrix = */ util::cast(matrix), + /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), + + /* .color_t = */ 0.f, + /* .blur_t = */ 0.f, + /* .opacity_t = */ 0.f, + /* .gapwidth_t = */ 0.f, + /* .offset_t = */ 0.f, + /* .width_t = */ 0.f, + /* .pad1 = */ 0 + }; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context); - drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &linePropertiesUBO, parameters.context); + drawableUniforms.createOrUpdate(idLineDrawableUBO, &drawableUBO, parameters.context, true); + drawableUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &propsUBO, parameters.context); // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty - assert(linePropertiesUBO.expressionMask == LineExpressionMask::None); + assert(propsUBO.expressionMask == LineExpressionMask::None); + + const LineExpressionUBO exprUBO = { + /* .color = */ nullptr, + /* .blur = */ nullptr, + /* .opacity = */ nullptr, + /* .gapwidth = */ nullptr, + /* .offset = */ nullptr, + /* .width = */ nullptr, + /* .floorWidth = */ nullptr, + }; + drawableUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, parameters.context); }; private: - shaders::LineEvaluatedPropsUBO linePropertiesUBO; + shaders::LineEvaluatedPropsUBO propsUBO; }; class WideVectorDrawableTweaker : public gfx::DrawableTweaker { @@ -216,22 +234,31 @@ class FillDrawableTweaker : public gfx::DrawableTweaker { const auto matrix = LayerTweaker::getTileMatrix( tileID, parameters, {{0, 0}}, style::TranslateAnchorType::Viewport, false, false, drawable, false); - const shaders::FillDrawableUBO fillDrawableUBO = {/* .matrix = */ util::cast(matrix), - - /* .color_t = */ 0.f, - /* .opacity_t = */ 0.f, - /* .pad1 = */ 0, - /* .pad2 = */ 0}; +#if MLN_UBO_CONSOLIDATION + shaders::FillDrawableUnionUBO drawableUBO; + drawableUBO.fillDrawableUBO = { +#else + const shaders::FillDrawableUBO drawableUBO = { +#endif + /* .matrix = */ util::cast(matrix), + + /* .color_t = */ 0.f, + /* .opacity_t = */ 0.f, + /* .pad1 = */ 0, + /* .pad2 = */ 0 + }; - const shaders::FillEvaluatedPropsUBO fillPropertiesUBO = {/* .color = */ color, - /* .outline_color = */ Color::white(), - /* .opacity = */ opacity, - /* .fade = */ 0.f, - /* .from_scale = */ 0.f, - /* .to_scale = */ 0.f}; + const shaders::FillEvaluatedPropsUBO propsUBO = { + /* .color = */ color, + /* .outline_color = */ Color::white(), + /* .opacity = */ opacity, + /* .fade = */ 0.f, + /* .from_scale = */ 0.f, + /* .to_scale = */ 0.f + }; auto& drawableUniforms = drawable.mutableUniformBuffers(); - drawableUniforms.createOrUpdate(idFillDrawableUBO, &fillDrawableUBO, parameters.context); - drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &fillPropertiesUBO, parameters.context); + drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, parameters.context); + drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &propsUBO, parameters.context); }; private: @@ -396,7 +423,6 @@ bool CustomDrawableLayerHost::Interface::addPolyline(const GeometryCoordinates& } bool CustomDrawableLayerHost::Interface::addFill(const GeometryCollection& geometry) { - return true; // build fill if (!updateBuilder(BuilderType::Fill, "custom-fill", fillShaderDefault())) return false; @@ -492,7 +518,7 @@ bool CustomDrawableLayerHost::Interface::addSymbol(const GeometryCoordinate& poi builder->setTexture(symbolOptions.texture, idCustomSymbolImageTexture); } - // create fill tweaker + // create symbol tweaker auto tweaker = std::make_shared(symbolOptions); builder->addTweaker(tweaker); diff --git a/src/mbgl/vulkan/buffer_resource.cpp b/src/mbgl/vulkan/buffer_resource.cpp index 2f9ccb4a45b..bff075701c5 100644 --- a/src/mbgl/vulkan/buffer_resource.cpp +++ b/src/mbgl/vulkan/buffer_resource.cpp @@ -56,13 +56,13 @@ BufferResource::BufferResource( std::size_t totalSize = size; // TODO -> check avg minUniformBufferOffsetAlignment vs individual buffers - if (usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) { + if (usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT || usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) { const auto& backend = context.getBackend(); const auto& deviceProps = backend.getDeviceProperties(); const auto& align = deviceProps.limits.minUniformBufferOffsetAlignment; bufferWindowSize = (size + align - 1) & ~(align - 1); - assert(bufferWindowSize != 0); + //assert(bufferWindowSize != 0); totalSize = bufferWindowSize * backend.getMaxFrames(); } diff --git a/src/mbgl/vulkan/context.cpp b/src/mbgl/vulkan/context.cpp index 1b6f97b9f5b..5e0dacd4f2b 100644 --- a/src/mbgl/vulkan/context.cpp +++ b/src/mbgl/vulkan/context.cpp @@ -51,7 +51,7 @@ class RenderbufferResource : public gfx::RenderbufferResource { Context::Context(RendererBackend& backend_) : gfx::Context(vulkan::maximumVertexBindingCount), backend(backend_), - globalUniformBuffers(DescriptorSetType::Global, 0, shaders::globalUBOCount) { + globalUniformBuffers(DescriptorSetType::Global, 0, 0, shaders::globalUBOCount) { if (glslangRefCount++ == 0) { glslang::InitializeProcess(); } @@ -73,19 +73,21 @@ void Context::initFrameResources() { const auto& device = backend.getDevice(); const auto frameCount = backend.getMaxFrames(); - descriptorPoolMap.emplace(DescriptorSetType::Global, - DescriptorPoolGrowable(globalDescriptorPoolSize, shaders::globalUBOCount)); + descriptorPoolMap.emplace( + DescriptorSetType::Global, + DescriptorPoolGrowable(globalDescriptorPoolSize, 0, shaders::globalUBOCount, 0)); - descriptorPoolMap.emplace(DescriptorSetType::Layer, - DescriptorPoolGrowable(layerDescriptorPoolSize, shaders::maxUBOCountPerLayer)); + descriptorPoolMap.emplace( + DescriptorSetType::Layer, + DescriptorPoolGrowable(layerDescriptorPoolSize, shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer, 0)); descriptorPoolMap.emplace( DescriptorSetType::DrawableUniform, - DescriptorPoolGrowable(drawableUniformDescriptorPoolSize, shaders::maxUBOCountPerDrawable)); + DescriptorPoolGrowable(drawableUniformDescriptorPoolSize, 0, shaders::maxUBOCountPerDrawable, 0)); descriptorPoolMap.emplace( DescriptorSetType::DrawableImage, - DescriptorPoolGrowable(drawableImageDescriptorPoolSize, shaders::maxTextureCountPerShader)); + DescriptorPoolGrowable(drawableImageDescriptorPoolSize, 0, 0, shaders::maxTextureCountPerShader)); // command buffers const vk::CommandBufferAllocateInfo allocateInfo( @@ -113,13 +115,15 @@ void Context::initFrameResources() { (void)getDummyTexture(); buildUniformDescriptorSetLayout( - globalUniformDescriptorSetLayout, 0, shaders::globalUBOCount, "GlobalUniformDescriptorSetLayout"); + globalUniformDescriptorSetLayout, 0, 0, shaders::globalUBOCount, "GlobalUniformDescriptorSetLayout"); buildUniformDescriptorSetLayout(layerUniformDescriptorSetLayout, - shaders::layerUBOStartId, + shaders::globalUBOCount, + shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer, "LayerUniformDescriptorSetLayout"); buildUniformDescriptorSetLayout(drawableUniformDescriptorSetLayout, shaders::globalUBOCount, + 0, shaders::maxUBOCountPerDrawable, "DrawableUniformDescriptorSetLayout"); buildImageDescriptorSetLayout(); @@ -357,8 +361,8 @@ gfx::UniqueDrawableBuilder Context::createDrawableBuilder(std::string name) { return std::make_unique(std::move(name)); } -gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool persistent) { - return std::make_shared(createBuffer(data, size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, persistent)); +gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool persistent, bool ssbo) { + return std::make_shared(createBuffer(data, size, ssbo ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, persistent)); } gfx::ShaderProgramBasePtr Context::getGenericShader(gfx::ShaderRegistry& shaders, const std::string& name) { @@ -572,6 +576,12 @@ const std::unique_ptr& Context::getDummyUniformBuffer() { return dummyUniformBuffer; } +const std::unique_ptr& Context::getDummyStorageBuffer() { + if (!dummyStorageBuffer) + dummyStorageBuffer = std::make_unique(*this, nullptr, 16, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, false); + return dummyStorageBuffer; +} + const std::unique_ptr& Context::getDummyTexture() { if (!dummyTexture2D) { const Size size(2, 2); @@ -590,23 +600,26 @@ const std::unique_ptr& Context::getDummyTexture() { } void Context::buildUniformDescriptorSetLayout(vk::UniqueDescriptorSetLayout& layout, - size_t uniformStartId, + size_t startId, + size_t storageCount, size_t uniformCount, const std::string& name) { std::vector bindings; - for (size_t i = 0; i < uniformCount; ++i) { + for (size_t i = 0; i < storageCount + uniformCount; ++i) { auto stageFlags = vk::ShaderStageFlags(); - if (uniformStartId + i != shaders::idDrawableReservedFragmentOnlyUBO) { + if (startId + i != shaders::idDrawableReservedFragmentOnlyUBO) { stageFlags |= vk::ShaderStageFlagBits::eVertex; } - if (uniformStartId + i != shaders::idDrawableReservedVertexOnlyUBO) { + if (startId + i != shaders::idDrawableReservedVertexOnlyUBO) { stageFlags |= vk::ShaderStageFlagBits::eFragment; } + const auto descriptorType = i < storageCount ? vk::DescriptorType::eStorageBuffer : vk::DescriptorType::eUniformBuffer; + bindings.push_back(vk::DescriptorSetLayoutBinding() .setBinding(static_cast(i)) .setStageFlags(stageFlags) - .setDescriptorType(vk::DescriptorType::eUniformBuffer) + .setDescriptorType(descriptorType) .setDescriptorCount(1)); } @@ -661,6 +674,9 @@ DescriptorPoolGrowable& Context::getDescriptorPool(DescriptorSetType type) { const vk::UniquePipelineLayout& Context::getGeneralPipelineLayout() { if (generalPipelineLayout) return generalPipelineLayout; + const auto stages = vk::ShaderStageFlags() | vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment; + const auto pushConstant = vk::PushConstantRange().setSize(sizeof(uint32_t)).setStageFlags(stages); + const std::vector layouts = { globalUniformDescriptorSetLayout.get(), layerUniformDescriptorSetLayout.get(), @@ -669,7 +685,7 @@ const vk::UniquePipelineLayout& Context::getGeneralPipelineLayout() { }; generalPipelineLayout = backend.getDevice()->createPipelineLayoutUnique( - vk::PipelineLayoutCreateInfo().setSetLayouts(layouts)); + vk::PipelineLayoutCreateInfo().setPushConstantRanges(pushConstant).setSetLayouts(layouts)); backend.setDebugName(generalPipelineLayout.get(), "PipelineLayout_general"); diff --git a/src/mbgl/vulkan/descriptor_set.cpp b/src/mbgl/vulkan/descriptor_set.cpp index f27f0a23c3e..8e13302b6f0 100644 --- a/src/mbgl/vulkan/descriptor_set.cpp +++ b/src/mbgl/vulkan/descriptor_set.cpp @@ -36,10 +36,6 @@ void DescriptorSet::createDescriptorPool(DescriptorPoolGrowable& growablePool) { const uint32_t maxSets = static_cast(growablePool.maxSets * std::pow(growablePool.growFactor, growablePool.pools.size())); - const vk::DescriptorPoolSize size = {type != DescriptorSetType::DrawableImage - ? vk::DescriptorType::eUniformBuffer - : vk::DescriptorType::eCombinedImageSampler, - maxSets * growablePool.descriptorsPerSet}; #ifdef USE_DESCRIPTOR_POOL_RESET const auto poolFlags = vk::DescriptorPoolCreateFlags(); @@ -47,7 +43,19 @@ void DescriptorSet::createDescriptorPool(DescriptorPoolGrowable& growablePool) { const auto poolFlags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet; #endif - const auto descriptorPoolInfo = vk::DescriptorPoolCreateInfo(poolFlags).setPoolSizes(size).setMaxSets(maxSets); + + std::vector sizes; + if (growablePool.descriptorStoragePerSet > 0) { + sizes.emplace_back(vk::DescriptorPoolSize(vk::DescriptorType::eStorageBuffer, maxSets * growablePool.descriptorStoragePerSet)); + } + if (growablePool.descriptorUniformsPerSet > 0) { + sizes.emplace_back(vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, maxSets * growablePool.descriptorUniformsPerSet)); + } + if (growablePool.descriptorTexturesPerSet > 0) { + sizes.emplace_back(vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, maxSets * growablePool.descriptorTexturesPerSet)); + } + + const auto descriptorPoolInfo = vk::DescriptorPoolCreateInfo(poolFlags).setPoolSizes(sizes).setMaxSets(maxSets); growablePool.pools.emplace_back(device->createDescriptorPoolUnique(descriptorPoolInfo), maxSets); growablePool.currentPoolIndex = static_cast(growablePool.pools.size() - 1); @@ -131,8 +139,9 @@ UniformDescriptorSet::UniformDescriptorSet(Context& context_, DescriptorSetType : DescriptorSet(context_, type_) {} void UniformDescriptorSet::update(const gfx::UniformBufferArray& uniforms, - uint32_t uniformStartIndex, - uint32_t descriptorBindingCount) { + uint32_t descriptorStartIndex, + uint32_t descriptorStorageCount, + uint32_t descriptorUniformCount) { MLN_TRACE_FUNC(); allocate(); @@ -144,25 +153,28 @@ void UniformDescriptorSet::update(const gfx::UniformBufferArray& uniforms, const auto& device = context.getBackend().getDevice(); - for (size_t index = 0; index < descriptorBindingCount; ++index) { + for (size_t index = 0; index < descriptorStorageCount + descriptorUniformCount; ++index) { vk::DescriptorBufferInfo descriptorBufferInfo; - if (const auto& uniformBuffer = uniforms.get(uniformStartIndex + index)) { + if (const auto& uniformBuffer = uniforms.get(descriptorStartIndex + index)) { const auto& uniformBufferImpl = static_cast(*uniformBuffer); const auto& bufferResource = uniformBufferImpl.getBufferResource(); descriptorBufferInfo.setBuffer(bufferResource.getVulkanBuffer()) .setOffset(bufferResource.getVulkanBufferOffset()) .setRange(bufferResource.getSizeInBytes()); } else { - descriptorBufferInfo.setBuffer(context.getDummyUniformBuffer()->getVulkanBuffer()) + const auto& dummyBuffer = index < descriptorStorageCount ? context.getDummyStorageBuffer() : context.getDummyUniformBuffer(); + descriptorBufferInfo.setBuffer(dummyBuffer->getVulkanBuffer()) .setOffset(0) .setRange(VK_WHOLE_SIZE); } + const auto descriptorType = index < descriptorStorageCount ? vk::DescriptorType::eStorageBuffer : vk::DescriptorType::eUniformBuffer; + const auto writeDescriptorSet = vk::WriteDescriptorSet() .setBufferInfo(descriptorBufferInfo) .setDescriptorCount(1) - .setDescriptorType(vk::DescriptorType::eUniformBuffer) + .setDescriptorType(descriptorType) .setDstBinding(static_cast(index)) .setDstSet(descriptorSets[frameIndex]); diff --git a/src/mbgl/vulkan/drawable.cpp b/src/mbgl/vulkan/drawable.cpp index 64dcf681ac0..e3b0cf45fc7 100644 --- a/src/mbgl/vulkan/drawable.cpp +++ b/src/mbgl/vulkan/drawable.cpp @@ -253,6 +253,13 @@ void Drawable::draw(PaintParameters& parameters) const { if (!bindAttributes(encoder)) return; if (!bindDescriptors(encoder)) return; + commandBuffer->pushConstants( + context.getGeneralPipelineLayout().get(), + vk::ShaderStageFlags() | vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment, + 0, + sizeof(uboIndex), + &uboIndex); + if (is3D) { impl->pipelineInfo.setDepthMode(impl->depthFor3D); impl->pipelineInfo.setStencilMode(impl->stencilFor3D); diff --git a/src/mbgl/vulkan/drawable_impl.hpp b/src/mbgl/vulkan/drawable_impl.hpp index b484ef533c1..432b93211b6 100644 --- a/src/mbgl/vulkan/drawable_impl.hpp +++ b/src/mbgl/vulkan/drawable_impl.hpp @@ -24,7 +24,7 @@ using namespace platform; class Drawable::Impl final { public: Impl() - : uniformBuffers(DescriptorSetType::DrawableUniform, shaders::globalUBOCount, shaders::maxUBOCountPerDrawable) { + : uniformBuffers(DescriptorSetType::DrawableUniform, shaders::globalUBOCount, 0, shaders::maxUBOCountPerDrawable) { } ~Impl() = default; diff --git a/src/mbgl/vulkan/layer_group.cpp b/src/mbgl/vulkan/layer_group.cpp index f86d556e037..0bbefe9f2ef 100644 --- a/src/mbgl/vulkan/layer_group.cpp +++ b/src/mbgl/vulkan/layer_group.cpp @@ -16,7 +16,7 @@ namespace vulkan { LayerGroup::LayerGroup(int32_t layerIndex_, std::size_t initialCapacity, std::string name_) : mbgl::LayerGroup(layerIndex_, initialCapacity, std::move(name_)), - uniformBuffers(DescriptorSetType::Layer, shaders::layerUBOStartId, shaders::maxUBOCountPerLayer) {} + uniformBuffers(DescriptorSetType::Layer, shaders::globalUBOCount, shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer) {} void LayerGroup::upload(gfx::UploadPass& uploadPass) { if (!enabled) { diff --git a/src/mbgl/vulkan/tile_layer_group.cpp b/src/mbgl/vulkan/tile_layer_group.cpp index ac56147305e..16246a98942 100644 --- a/src/mbgl/vulkan/tile_layer_group.cpp +++ b/src/mbgl/vulkan/tile_layer_group.cpp @@ -17,7 +17,7 @@ namespace vulkan { TileLayerGroup::TileLayerGroup(int32_t layerIndex_, std::size_t initialCapacity, std::string name_) : mbgl::TileLayerGroup(layerIndex_, initialCapacity, std::move(name_)), - uniformBuffers(DescriptorSetType::Layer, shaders::layerUBOStartId, shaders::maxUBOCountPerLayer) {} + uniformBuffers(DescriptorSetType::Layer, shaders::globalUBOCount, shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer) {} void TileLayerGroup::upload(gfx::UploadPass& uploadPass) { if (!enabled || !getDrawableCount()) { diff --git a/src/mbgl/vulkan/uniform_buffer.cpp b/src/mbgl/vulkan/uniform_buffer.cpp index b01e0facc90..6a4ee1e0e16 100644 --- a/src/mbgl/vulkan/uniform_buffer.cpp +++ b/src/mbgl/vulkan/uniform_buffer.cpp @@ -26,17 +26,17 @@ UniformBuffer::~UniformBuffer() { } void UniformBuffer::update(const void* data, std::size_t size_) { - assert(size == size_); + /*assert(size == size_); if (size != size_ || size != buffer.getSizeInBytes()) { Log::Error( Event::General, "Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_)); return; - } + }*/ buffer.getContext().renderingStats().numUniformUpdates++; buffer.getContext().renderingStats().uniformUpdateBytes += size_; - buffer.update(data, size, /*offset=*/0); + buffer.update(data, size_, /*offset=*/0); } const std::shared_ptr& UniformBufferArray::set(const size_t id, @@ -73,7 +73,7 @@ void UniformBufferArray::bindDescriptorSets(CommandEncoder& encoder) { descriptorSet = std::make_unique(encoder.getContext(), descriptorSetType); } - descriptorSet->update(*this, descriptorStartIndex, descriptorBindingCount); + descriptorSet->update(*this, descriptorStartIndex, descriptorStorageCount, descriptorUniformCount); descriptorSet->bind(encoder); } From edcabc78a623aab0c73c0ceeeed2522b403c3f56 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Dec 2024 20:54:06 +0000 Subject: [PATCH 11/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- include/mbgl/gfx/context.hpp | 5 +++- include/mbgl/mtl/context.hpp | 5 +++- include/mbgl/vulkan/context.hpp | 5 +++- include/mbgl/vulkan/descriptor_set.hpp | 5 +++- src/mbgl/gl/context.cpp | 5 +++- src/mbgl/gl/context.hpp | 5 +++- .../layers/background_layer_tweaker.cpp | 3 ++- .../renderer/layers/circle_layer_tweaker.cpp | 3 ++- .../layers/fill_extrusion_layer_tweaker.cpp | 6 +++-- .../renderer/layers/fill_layer_tweaker.cpp | 6 +++-- .../renderer/layers/heatmap_layer_tweaker.cpp | 3 ++- .../layers/hillshade_layer_tweaker.cpp | 6 +++-- .../renderer/layers/line_layer_tweaker.cpp | 6 +++-- .../renderer/layers/raster_layer_tweaker.cpp | 3 ++- .../renderer/layers/symbol_layer_tweaker.cpp | 6 +++-- src/mbgl/renderer/renderer_impl.cpp | 2 +- .../renderer/sources/render_tile_source.cpp | 23 ++++++++++--------- .../style/layers/custom_drawable_layer.cpp | 20 ++++++++-------- src/mbgl/vulkan/buffer_resource.cpp | 2 +- src/mbgl/vulkan/context.cpp | 17 ++++++++------ src/mbgl/vulkan/descriptor_set.cpp | 20 ++++++++-------- src/mbgl/vulkan/drawable_impl.hpp | 4 ++-- src/mbgl/vulkan/layer_group.cpp | 5 +++- src/mbgl/vulkan/tile_layer_group.cpp | 5 +++- 24 files changed, 106 insertions(+), 64 deletions(-) diff --git a/include/mbgl/gfx/context.hpp b/include/mbgl/gfx/context.hpp index 921374d4281..abfdd383e95 100644 --- a/include/mbgl/gfx/context.hpp +++ b/include/mbgl/gfx/context.hpp @@ -125,7 +125,10 @@ class Context { /// @param data The data to copy, may be `nullptr` /// @param size The size of the buffer /// @param persistent Performance hint, optimize for few or many uses - virtual UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false, bool ssbo = false) = 0; + virtual UniformBufferPtr createUniformBuffer(const void* data, + std::size_t size, + bool persistent = false, + bool ssbo = false) = 0; /// Get the generic shader with the specified name virtual gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) = 0; diff --git a/include/mbgl/mtl/context.hpp b/include/mbgl/mtl/context.hpp index a6349faf942..41c354b4dde 100644 --- a/include/mbgl/mtl/context.hpp +++ b/include/mbgl/mtl/context.hpp @@ -83,7 +83,10 @@ class Context final : public gfx::Context { void reduceMemoryUsage() override {} gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override; - gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false, bool ssbo = false) override; + gfx::UniformBufferPtr createUniformBuffer(const void* data, + std::size_t size, + bool persistent = false, + bool ssbo = false) override; gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override; diff --git a/include/mbgl/vulkan/context.hpp b/include/mbgl/vulkan/context.hpp index eb6ea156631..abbc9e3985a 100644 --- a/include/mbgl/vulkan/context.hpp +++ b/include/mbgl/vulkan/context.hpp @@ -74,7 +74,10 @@ class Context final : public gfx::Context { void reduceMemoryUsage() override {} gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override; - gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent, bool ssbo = false) override; + gfx::UniformBufferPtr createUniformBuffer(const void* data, + std::size_t size, + bool persistent, + bool ssbo = false) override; gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override; diff --git a/include/mbgl/vulkan/descriptor_set.hpp b/include/mbgl/vulkan/descriptor_set.hpp index 6582216c956..b1c4619c542 100644 --- a/include/mbgl/vulkan/descriptor_set.hpp +++ b/include/mbgl/vulkan/descriptor_set.hpp @@ -80,7 +80,10 @@ class UniformDescriptorSet : public DescriptorSet { UniformDescriptorSet(Context& context_, DescriptorSetType type_); virtual ~UniformDescriptorSet() = default; - void update(const gfx::UniformBufferArray& uniforms, uint32_t descriptorStartIndex, uint32_t descriptorStorageCount, uint32_t descriptorUniformCount); + void update(const gfx::UniformBufferArray& uniforms, + uint32_t descriptorStartIndex, + uint32_t descriptorStorageCount, + uint32_t descriptorUniformCount); }; class ImageDescriptorSet : public DescriptorSet { diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 6e95f3df7d5..d8a8dcac2b7 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -611,7 +611,10 @@ gfx::UniqueDrawableBuilder Context::createDrawableBuilder(std::string name) { return std::make_unique(std::move(name)); } -gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool /*persistent*/, bool /*ssbo*/) { +gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, + std::size_t size, + bool /*persistent*/, + bool /*ssbo*/) { MLN_TRACE_FUNC(); return std::make_shared(data, size, *uboAllocator); diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 0b42d58f844..0c34475a9a9 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -120,7 +120,10 @@ class Context final : public gfx::Context { #if MLN_DRAWABLE_RENDERER gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override; - gfx::UniformBufferPtr createUniformBuffer(const void* data, std::size_t size, bool persistent = false, bool ssbo = false) override; + gfx::UniformBufferPtr createUniformBuffer(const void* data, + std::size_t size, + bool persistent = false, + bool ssbo = false) override; gfx::ShaderProgramBasePtr getGenericShader(gfx::ShaderRegistry&, const std::string& name) override; diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index dbfca5ef36c..2cccad00704 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -148,7 +148,8 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(BackgroundDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index 3b3ac5f6f50..c57a3eb31f8 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -118,7 +118,8 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(CircleDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index 044452fabfd..73b61aca4a5 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -155,14 +155,16 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(FillExtrusionDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(FillExtrusionTilePropsUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); + tilePropsUniformBuffer = context.createUniformBuffer( + tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 8530629f11d..3058fe8dc19 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -252,14 +252,16 @@ void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(FillDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(FillTilePropsUnionUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); + tilePropsUniformBuffer = context.createUniformBuffer( + tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index 5572a8ba1ac..7d3e45c5a4f 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -93,7 +93,8 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(HeatmapDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index db085271f14..510c700ed75 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -100,14 +100,16 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam auto& context = parameters.context; const size_t drawableUBOVectorSize = sizeof(HillshadeDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(HillshadeTilePropsUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); + tilePropsUniformBuffer = context.createUniformBuffer( + tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 87596e1f7c6..888a83011e2 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -364,14 +364,16 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(LineDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(LineTilePropsUnionUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); + tilePropsUniformBuffer = context.createUniformBuffer( + tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index 0303017fc19..e195d3b681d 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -119,7 +119,8 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, auto& context = parameters.context; const size_t drawableUBOVectorSize = sizeof(RasterDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index e2e7a8ea781..d99a5d6875f 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -203,14 +203,16 @@ void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(SymbolDrawableUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } const size_t tilePropsUBOVectorSize = sizeof(SymbolTilePropsUBO) * tilePropsUBOVector.size(); if (!tilePropsUniformBuffer || tilePropsUniformBuffer->getSize() < tilePropsUBOVectorSize) { - tilePropsUniformBuffer = context.createUniformBuffer(tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); + tilePropsUniformBuffer = context.createUniformBuffer( + tilePropsUBOVector.data(), tilePropsUBOVectorSize, false, true); } else { tilePropsUniformBuffer->update(tilePropsUBOVector.data(), tilePropsUBOVectorSize); } diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index bd3631d4af0..f28165ca2c8 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -253,7 +253,7 @@ void Renderer::Impl::render(const RenderTree& renderTree, // Update the debug layer groups orchestrator.updateDebugLayerGroups(renderTree, parameters); - + // Tweakers are run in the upload pass so they can set up uniforms. parameters.currentLayer = 0; orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) { diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 5a0ebe4b8a1..1f19253121b 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -108,7 +108,7 @@ class PolylineLayerTweaker : public LayerTweaker { /* .floorWidth = */ nullptr, }; layerUniforms.createOrUpdate(idLineExpressionUBO, &exprUBO, context); - + #if MLN_UBO_CONSOLIDATION int i = 0; std::vector drawableUBOVector(layerGroup.getDrawableCount()); @@ -140,7 +140,8 @@ class PolylineLayerTweaker : public LayerTweaker { /* .gapwidth_t = */ 0.f, /* .offset_t = */ 0.f, /* .width_t = */ 0.f, - /* .pad1 = */ 0}; + /* .pad1 = */ 0 + }; #if MLN_UBO_CONSOLIDATION drawable.setUBOIndex(i++); @@ -153,7 +154,8 @@ class PolylineLayerTweaker : public LayerTweaker { #if MLN_UBO_CONSOLIDATION const size_t drawableUBOVectorSize = sizeof(LineDrawableUnionUBO) * drawableUBOVector.size(); if (!drawableUniformBuffer || drawableUniformBuffer->getSize() < drawableUBOVectorSize) { - drawableUniformBuffer = context.createUniformBuffer(drawableUBOVector.data(), drawableUBOVectorSize, false, true); + drawableUniformBuffer = context.createUniformBuffer( + drawableUBOVector.data(), drawableUBOVectorSize, false, true); } else { drawableUniformBuffer->update(drawableUBOVector.data(), drawableUBOVectorSize); } @@ -336,7 +338,7 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr drawable->setTileID(tile.getOverscaledTileID()); tileLayerGroup->addDrawable(renderPass, tile.getOverscaledTileID(), std::move(drawable)); } - + if (!layerTweaker) { layerTweaker = std::make_shared(linePropertiesUBO); tileLayerGroup->addLayerTweaker(layerTweaker); @@ -428,13 +430,12 @@ void TileSourceRenderItem::updateDebugDrawables(DebugLayerGroupMap& debugLayerGr addPolylineDrawable(tileLayerGroup, tile); } #else - const DebugUBO debugUBO = { - /* .matrix = */ util::cast(tile.matrix), - /* .color = */ Color::red(), - /* .overlay_scale = */ 1.0f, - /* .pad1 = */ 0, - /* .pad2 = */ 0, - /* .pad3 = */ 0}; + const DebugUBO debugUBO = {/* .matrix = */ util::cast(tile.matrix), + /* .color = */ Color::red(), + /* .overlay_scale = */ 1.0f, + /* .pad1 = */ 0, + /* .pad2 = */ 0, + /* .pad3 = */ 0}; if (0 == updateDrawables(tileLayerGroup, tileID, debugUBO) && tile.getNeedsRendering()) { addDrawable(tileLayerGroup, diff --git a/src/mbgl/style/layers/custom_drawable_layer.cpp b/src/mbgl/style/layers/custom_drawable_layer.cpp index 45477520a95..6ffd5a4bc41 100644 --- a/src/mbgl/style/layers/custom_drawable_layer.cpp +++ b/src/mbgl/style/layers/custom_drawable_layer.cpp @@ -116,7 +116,7 @@ class LineDrawableTweaker : public gfx::DrawableTweaker { #endif /* .matrix = */ util::cast(matrix), /* .ratio = */ 1.0f / tileID.pixelsToTileUnits(1.0f, zoom), - + /* .color_t = */ 0.f, /* .blur_t = */ 0.f, /* .opacity_t = */ 0.f, @@ -131,7 +131,7 @@ class LineDrawableTweaker : public gfx::DrawableTweaker { // We would need to set up `idLineExpressionUBO` if the expression mask isn't empty assert(propsUBO.expressionMask == LineExpressionMask::None); - + const LineExpressionUBO exprUBO = { /* .color = */ nullptr, /* .blur = */ nullptr, @@ -241,21 +241,19 @@ class FillDrawableTweaker : public gfx::DrawableTweaker { const shaders::FillDrawableUBO drawableUBO = { #endif /* .matrix = */ util::cast(matrix), - + /* .color_t = */ 0.f, /* .opacity_t = */ 0.f, /* .pad1 = */ 0, /* .pad2 = */ 0 }; - const shaders::FillEvaluatedPropsUBO propsUBO = { - /* .color = */ color, - /* .outline_color = */ Color::white(), - /* .opacity = */ opacity, - /* .fade = */ 0.f, - /* .from_scale = */ 0.f, - /* .to_scale = */ 0.f - }; + const shaders::FillEvaluatedPropsUBO propsUBO = {/* .color = */ color, + /* .outline_color = */ Color::white(), + /* .opacity = */ opacity, + /* .fade = */ 0.f, + /* .from_scale = */ 0.f, + /* .to_scale = */ 0.f}; auto& drawableUniforms = drawable.mutableUniformBuffers(); drawableUniforms.createOrUpdate(idFillDrawableUBO, &drawableUBO, parameters.context); drawableUniforms.createOrUpdate(idFillEvaluatedPropsUBO, &propsUBO, parameters.context); diff --git a/src/mbgl/vulkan/buffer_resource.cpp b/src/mbgl/vulkan/buffer_resource.cpp index bff075701c5..c86365bc29e 100644 --- a/src/mbgl/vulkan/buffer_resource.cpp +++ b/src/mbgl/vulkan/buffer_resource.cpp @@ -62,7 +62,7 @@ BufferResource::BufferResource( const auto& align = deviceProps.limits.minUniformBufferOffsetAlignment; bufferWindowSize = (size + align - 1) & ~(align - 1); - //assert(bufferWindowSize != 0); + // assert(bufferWindowSize != 0); totalSize = bufferWindowSize * backend.getMaxFrames(); } diff --git a/src/mbgl/vulkan/context.cpp b/src/mbgl/vulkan/context.cpp index 5e0dacd4f2b..c7c11e5396c 100644 --- a/src/mbgl/vulkan/context.cpp +++ b/src/mbgl/vulkan/context.cpp @@ -73,13 +73,13 @@ void Context::initFrameResources() { const auto& device = backend.getDevice(); const auto frameCount = backend.getMaxFrames(); - descriptorPoolMap.emplace( - DescriptorSetType::Global, - DescriptorPoolGrowable(globalDescriptorPoolSize, 0, shaders::globalUBOCount, 0)); + descriptorPoolMap.emplace(DescriptorSetType::Global, + DescriptorPoolGrowable(globalDescriptorPoolSize, 0, shaders::globalUBOCount, 0)); descriptorPoolMap.emplace( DescriptorSetType::Layer, - DescriptorPoolGrowable(layerDescriptorPoolSize, shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer, 0)); + DescriptorPoolGrowable( + layerDescriptorPoolSize, shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer, 0)); descriptorPoolMap.emplace( DescriptorSetType::DrawableUniform, @@ -362,7 +362,8 @@ gfx::UniqueDrawableBuilder Context::createDrawableBuilder(std::string name) { } gfx::UniformBufferPtr Context::createUniformBuffer(const void* data, std::size_t size, bool persistent, bool ssbo) { - return std::make_shared(createBuffer(data, size, ssbo ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, persistent)); + return std::make_shared(createBuffer( + data, size, ssbo ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, persistent)); } gfx::ShaderProgramBasePtr Context::getGenericShader(gfx::ShaderRegistry& shaders, const std::string& name) { @@ -578,7 +579,8 @@ const std::unique_ptr& Context::getDummyUniformBuffer() { const std::unique_ptr& Context::getDummyStorageBuffer() { if (!dummyStorageBuffer) - dummyStorageBuffer = std::make_unique(*this, nullptr, 16, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, false); + dummyStorageBuffer = std::make_unique( + *this, nullptr, 16, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, false); return dummyStorageBuffer; } @@ -614,7 +616,8 @@ void Context::buildUniformDescriptorSetLayout(vk::UniqueDescriptorSetLayout& lay stageFlags |= vk::ShaderStageFlagBits::eFragment; } - const auto descriptorType = i < storageCount ? vk::DescriptorType::eStorageBuffer : vk::DescriptorType::eUniformBuffer; + const auto descriptorType = i < storageCount ? vk::DescriptorType::eStorageBuffer + : vk::DescriptorType::eUniformBuffer; bindings.push_back(vk::DescriptorSetLayoutBinding() .setBinding(static_cast(i)) diff --git a/src/mbgl/vulkan/descriptor_set.cpp b/src/mbgl/vulkan/descriptor_set.cpp index 8e13302b6f0..ed688f92d05 100644 --- a/src/mbgl/vulkan/descriptor_set.cpp +++ b/src/mbgl/vulkan/descriptor_set.cpp @@ -43,16 +43,18 @@ void DescriptorSet::createDescriptorPool(DescriptorPoolGrowable& growablePool) { const auto poolFlags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet; #endif - std::vector sizes; if (growablePool.descriptorStoragePerSet > 0) { - sizes.emplace_back(vk::DescriptorPoolSize(vk::DescriptorType::eStorageBuffer, maxSets * growablePool.descriptorStoragePerSet)); + sizes.emplace_back( + vk::DescriptorPoolSize(vk::DescriptorType::eStorageBuffer, maxSets * growablePool.descriptorStoragePerSet)); } if (growablePool.descriptorUniformsPerSet > 0) { - sizes.emplace_back(vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, maxSets * growablePool.descriptorUniformsPerSet)); + sizes.emplace_back(vk::DescriptorPoolSize(vk::DescriptorType::eUniformBuffer, + maxSets * growablePool.descriptorUniformsPerSet)); } if (growablePool.descriptorTexturesPerSet > 0) { - sizes.emplace_back(vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, maxSets * growablePool.descriptorTexturesPerSet)); + sizes.emplace_back(vk::DescriptorPoolSize(vk::DescriptorType::eCombinedImageSampler, + maxSets * growablePool.descriptorTexturesPerSet)); } const auto descriptorPoolInfo = vk::DescriptorPoolCreateInfo(poolFlags).setPoolSizes(sizes).setMaxSets(maxSets); @@ -163,13 +165,13 @@ void UniformDescriptorSet::update(const gfx::UniformBufferArray& uniforms, .setOffset(bufferResource.getVulkanBufferOffset()) .setRange(bufferResource.getSizeInBytes()); } else { - const auto& dummyBuffer = index < descriptorStorageCount ? context.getDummyStorageBuffer() : context.getDummyUniformBuffer(); - descriptorBufferInfo.setBuffer(dummyBuffer->getVulkanBuffer()) - .setOffset(0) - .setRange(VK_WHOLE_SIZE); + const auto& dummyBuffer = index < descriptorStorageCount ? context.getDummyStorageBuffer() + : context.getDummyUniformBuffer(); + descriptorBufferInfo.setBuffer(dummyBuffer->getVulkanBuffer()).setOffset(0).setRange(VK_WHOLE_SIZE); } - const auto descriptorType = index < descriptorStorageCount ? vk::DescriptorType::eStorageBuffer : vk::DescriptorType::eUniformBuffer; + const auto descriptorType = index < descriptorStorageCount ? vk::DescriptorType::eStorageBuffer + : vk::DescriptorType::eUniformBuffer; const auto writeDescriptorSet = vk::WriteDescriptorSet() .setBufferInfo(descriptorBufferInfo) diff --git a/src/mbgl/vulkan/drawable_impl.hpp b/src/mbgl/vulkan/drawable_impl.hpp index 432b93211b6..a159fa6adc0 100644 --- a/src/mbgl/vulkan/drawable_impl.hpp +++ b/src/mbgl/vulkan/drawable_impl.hpp @@ -24,8 +24,8 @@ using namespace platform; class Drawable::Impl final { public: Impl() - : uniformBuffers(DescriptorSetType::DrawableUniform, shaders::globalUBOCount, 0, shaders::maxUBOCountPerDrawable) { - } + : uniformBuffers( + DescriptorSetType::DrawableUniform, shaders::globalUBOCount, 0, shaders::maxUBOCountPerDrawable) {} ~Impl() = default; diff --git a/src/mbgl/vulkan/layer_group.cpp b/src/mbgl/vulkan/layer_group.cpp index 0bbefe9f2ef..9d9d57fba07 100644 --- a/src/mbgl/vulkan/layer_group.cpp +++ b/src/mbgl/vulkan/layer_group.cpp @@ -16,7 +16,10 @@ namespace vulkan { LayerGroup::LayerGroup(int32_t layerIndex_, std::size_t initialCapacity, std::string name_) : mbgl::LayerGroup(layerIndex_, initialCapacity, std::move(name_)), - uniformBuffers(DescriptorSetType::Layer, shaders::globalUBOCount, shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer) {} + uniformBuffers(DescriptorSetType::Layer, + shaders::globalUBOCount, + shaders::maxSSBOCountPerLayer, + shaders::maxUBOCountPerLayer) {} void LayerGroup::upload(gfx::UploadPass& uploadPass) { if (!enabled) { diff --git a/src/mbgl/vulkan/tile_layer_group.cpp b/src/mbgl/vulkan/tile_layer_group.cpp index 16246a98942..f1326b13b6f 100644 --- a/src/mbgl/vulkan/tile_layer_group.cpp +++ b/src/mbgl/vulkan/tile_layer_group.cpp @@ -17,7 +17,10 @@ namespace vulkan { TileLayerGroup::TileLayerGroup(int32_t layerIndex_, std::size_t initialCapacity, std::string name_) : mbgl::TileLayerGroup(layerIndex_, initialCapacity, std::move(name_)), - uniformBuffers(DescriptorSetType::Layer, shaders::globalUBOCount, shaders::maxSSBOCountPerLayer, shaders::maxUBOCountPerLayer) {} + uniformBuffers(DescriptorSetType::Layer, + shaders::globalUBOCount, + shaders::maxSSBOCountPerLayer, + shaders::maxUBOCountPerLayer) {} void TileLayerGroup::upload(gfx::UploadPass& uploadPass) { if (!enabled || !getDrawableCount()) { From 20bd89837f79d807af93923de156655053d6f150 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Mon, 16 Dec 2024 15:31:57 +0200 Subject: [PATCH 12/13] Fixes. --- include/mbgl/gfx/uniform_buffer.hpp | 2 +- include/mbgl/gl/uniform_buffer_gl.hpp | 2 +- include/mbgl/mtl/uniform_buffer.hpp | 2 +- include/mbgl/vulkan/uniform_buffer.hpp | 2 +- src/mbgl/gl/uniform_buffer_gl.cpp | 14 +++++++------- src/mbgl/mtl/uniform_buffer.cpp | 14 +++++++------- .../renderer/layers/background_layer_tweaker.cpp | 6 +++--- src/mbgl/renderer/layers/circle_layer_tweaker.cpp | 6 +++--- .../layers/fill_extrusion_layer_tweaker.cpp | 8 ++++---- src/mbgl/renderer/layers/fill_layer_tweaker.cpp | 8 ++++---- src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp | 8 ++++---- .../layers/heatmap_texture_layer_tweaker.cpp | 4 ++-- .../renderer/layers/hillshade_layer_tweaker.cpp | 4 ++-- src/mbgl/renderer/layers/line_layer_tweaker.cpp | 4 ++++ src/mbgl/renderer/layers/raster_layer_tweaker.cpp | 4 ++++ src/mbgl/renderer/layers/symbol_layer_tweaker.cpp | 8 ++++---- src/mbgl/renderer/sources/render_tile_source.cpp | 4 ++++ src/mbgl/vulkan/buffer_resource.cpp | 2 +- src/mbgl/vulkan/uniform_buffer.cpp | 14 +++++++------- 19 files changed, 64 insertions(+), 52 deletions(-) diff --git a/include/mbgl/gfx/uniform_buffer.hpp b/include/mbgl/gfx/uniform_buffer.hpp index d1acdc94ae2..390459c5748 100644 --- a/include/mbgl/gfx/uniform_buffer.hpp +++ b/include/mbgl/gfx/uniform_buffer.hpp @@ -29,7 +29,7 @@ class UniformBuffer { public: virtual ~UniformBuffer() = default; - virtual void update(const void* data, std::size_t size_) = 0; + virtual void update(const void* data, std::size_t dataSize) = 0; std::size_t getSize() const { return size; } diff --git a/include/mbgl/gl/uniform_buffer_gl.hpp b/include/mbgl/gl/uniform_buffer_gl.hpp index 770c5c4bb61..b186715e9c5 100644 --- a/include/mbgl/gl/uniform_buffer_gl.hpp +++ b/include/mbgl/gl/uniform_buffer_gl.hpp @@ -24,7 +24,7 @@ class UniformBufferGL final : public gfx::UniformBuffer { UniformBufferGL clone() const { return {*this}; } // gfx::UniformBuffer - void update(const void* data, std::size_t size_) override; + void update(const void* data, std::size_t dataSize) override; private: // unique id used for debugging and profiling purposes diff --git a/include/mbgl/mtl/uniform_buffer.hpp b/include/mbgl/mtl/uniform_buffer.hpp index 399f122b706..9dfbdb1a8ab 100644 --- a/include/mbgl/mtl/uniform_buffer.hpp +++ b/include/mbgl/mtl/uniform_buffer.hpp @@ -19,7 +19,7 @@ class UniformBuffer final : public gfx::UniformBuffer { UniformBuffer clone() const { return {buffer.clone()}; } - void update(const void* data, std::size_t size_) override; + void update(const void* data, std::size_t dataSize) override; protected: BufferResource buffer; diff --git a/include/mbgl/vulkan/uniform_buffer.hpp b/include/mbgl/vulkan/uniform_buffer.hpp index 643f293e955..23d1cac2d0b 100644 --- a/include/mbgl/vulkan/uniform_buffer.hpp +++ b/include/mbgl/vulkan/uniform_buffer.hpp @@ -18,7 +18,7 @@ class UniformBuffer final : public gfx::UniformBuffer { UniformBuffer clone() const { return {buffer.clone()}; } - void update(const void* data, std::size_t size_) override; + void update(const void* data, std::size_t dataSize) override; protected: BufferResource buffer; diff --git a/src/mbgl/gl/uniform_buffer_gl.cpp b/src/mbgl/gl/uniform_buffer_gl.cpp index c1b1814b55b..4f1a9a739af 100644 --- a/src/mbgl/gl/uniform_buffer_gl.cpp +++ b/src/mbgl/gl/uniform_buffer_gl.cpp @@ -102,25 +102,25 @@ BufferID UniformBufferGL::getID() const { } } -void UniformBufferGL::update(const void* data_, std::size_t size_) { - assert(isManagedAllocation ? managedBuffer.getContents().size() == size_ : size == size_); +void UniformBufferGL::update(const void* data, std::size_t dataSize) { + assert(isManagedAllocation ? dataSize <= managedBuffer.getContents().size() : dataSize <= size); - if (size != size_ || (isManagedAllocation && managedBuffer.getContents().size() != size_)) { + if (dataSize > size || (isManagedAllocation && dataSize > managedBuffer.getContents().size())) { Log::Error( Event::General, - "Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_)); + "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + std::to_string(dataSize)); return; } - if (std::memcmp(data_, managedBuffer.getContents().data(), managedBuffer.getContents().size()) == 0) { + if (std::memcmp(data, managedBuffer.getContents().data(), dataSize) == 0) { return; } if (isManagedAllocation) { - managedBuffer.allocate(data_, size); + managedBuffer.allocate(data, dataSize); } else { MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, localID)); - MBGL_CHECK_ERROR(glBufferSubData(GL_UNIFORM_BUFFER, 0, size_, data_)); + MBGL_CHECK_ERROR(glBufferSubData(GL_UNIFORM_BUFFER, 0, dataSize, data)); MBGL_CHECK_ERROR(glBindBuffer(GL_UNIFORM_BUFFER, 0)); } } diff --git a/src/mbgl/mtl/uniform_buffer.cpp b/src/mbgl/mtl/uniform_buffer.cpp index 4349af8a93b..febf2235f36 100644 --- a/src/mbgl/mtl/uniform_buffer.cpp +++ b/src/mbgl/mtl/uniform_buffer.cpp @@ -25,18 +25,18 @@ UniformBuffer::~UniformBuffer() { buffer.getContext().renderingStats().memUniformBuffers -= size; } -void UniformBuffer::update(const void* data, std::size_t size_) { - /*assert(size == size_); - if (size != size_ || size != buffer.getSizeInBytes()) { +void UniformBuffer::update(const void* data, std::size_t dataSize) { + assert(dataSize <= size); + if (dataSize > size || dataSize > buffer.getSizeInBytes()) { Log::Error( Event::General, - "Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_)); + "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + std::to_string(dataSize)); return; - }*/ + } buffer.getContext().renderingStats().numUniformUpdates++; - buffer.getContext().renderingStats().uniformUpdateBytes += size_; - buffer.update(data, size_, /*offset=*/0); + buffer.getContext().renderingStats().uniformUpdateBytes += dataSize; + buffer.update(data, dataSize, /*offset=*/0); } void UniformBufferArray::bind(RenderPass& renderPass) const noexcept { diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index 2cccad00704..b657f2f0b83 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -20,13 +20,13 @@ constexpr auto BackgroundPatternShaderName = "BackgroundPatternShader"; #endif void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { - const auto& state = parameters.state; - auto& context = parameters.context; - if (layerGroup.empty()) { return; } + const auto& state = parameters.state; + auto& context = parameters.context; + #if defined(DEBUG) const auto label = layerGroup.getName() + "-update-uniforms"; const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index c57a3eb31f8..e8c674392aa 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -23,13 +23,13 @@ using namespace style; using namespace shaders; void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { - auto& context = parameters.context; - const auto& evaluated = static_cast(*evaluatedProperties).evaluated; - if (layerGroup.empty()) { return; } + auto& context = parameters.context; + const auto& evaluated = static_cast(*evaluatedProperties).evaluated; + #if !defined(NDEBUG) const auto label = layerGroup.getName() + "-update-uniforms"; const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index 73b61aca4a5..becf5863dcf 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -24,16 +24,16 @@ using namespace shaders; using namespace style; void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { + if (layerGroup.empty()) { + return; + } + auto& context = parameters.context; const auto& props = static_cast(*evaluatedProperties); const auto& evaluated = props.evaluated; const auto& crossfade = props.crossfade; const auto& state = parameters.state; - if (layerGroup.empty()) { - return; - } - #if !defined(NDEBUG) const auto label = layerGroup.getName() + "-update-uniforms"; const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); diff --git a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp index 3058fe8dc19..398c9dc87ac 100644 --- a/src/mbgl/renderer/layers/fill_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_layer_tweaker.cpp @@ -23,15 +23,15 @@ using namespace style; using namespace shaders; void FillLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { + if (layerGroup.empty()) { + return; + } + auto& context = parameters.context; const auto& props = static_cast(*evaluatedProperties); const auto& evaluated = props.evaluated; const auto& crossfade = props.crossfade; - if (layerGroup.empty()) { - return; - } - #if !defined(NDEBUG) const auto label = layerGroup.getName() + "-update-uniforms"; const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index 7d3e45c5a4f..9172150e805 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -21,14 +21,14 @@ using namespace style; using namespace shaders; void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { - auto& context = parameters.context; - const auto zoom = static_cast(parameters.state.getZoom()); - const auto& evaluated = static_cast(*evaluatedProperties).evaluated; - if (layerGroup.empty()) { return; } + auto& context = parameters.context; + const auto zoom = static_cast(parameters.state.getZoom()); + const auto& evaluated = static_cast(*evaluatedProperties).evaluated; + #if !defined(NDEBUG) const auto label = layerGroup.getName() + "-update-uniforms"; const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index 165958c16f6..889ecfabed3 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -16,12 +16,12 @@ using namespace style; using namespace shaders; void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { - const auto& evaluated = static_cast(*evaluatedProperties).evaluated; - if (layerGroup.empty()) { return; } + const auto& evaluated = static_cast(*evaluatedProperties).evaluated; + #if !defined(NDEBUG) const auto label = layerGroup.getName() + "-update-uniforms"; const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index 510c700ed75..d7c6d2b2334 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -32,12 +32,12 @@ std::array getLight(const PaintParameters& parameters, } // namespace void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { - const auto& evaluated = static_cast(*evaluatedProperties).evaluated; - if (layerGroup.empty()) { return; } + const auto& evaluated = static_cast(*evaluatedProperties).evaluated; + #if !defined(NDEBUG) const auto label = layerGroup.getName() + "-update-uniforms"; const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 888a83011e2..93591f92d4a 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -66,6 +66,10 @@ auto LineLayerTweaker::evaluate([[maybe_unused]] const PaintParameters& paramete } void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { + if (layerGroup.empty()) { + return; + } + auto& context = parameters.context; const auto& evaluated = static_cast(*evaluatedProperties).evaluated; const auto& crossfade = static_cast(*evaluatedProperties).crossfade; diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index e195d3b681d..7a89414e1db 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -18,6 +18,10 @@ using namespace shaders; void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, [[maybe_unused]] const PaintParameters& parameters) { + if (layerGroup.empty()) { + return; + } + const auto& evaluated = static_cast(*evaluatedProperties).evaluated; const auto spinWeights = [](float spin) -> std::array { diff --git a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp index d99a5d6875f..9f737ded608 100644 --- a/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/symbol_layer_tweaker.cpp @@ -53,14 +53,14 @@ auto getInterpFactor(const SymbolBucket::PaintProperties& paintProps, bool isTex } // namespace void SymbolLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { - auto& context = parameters.context; - const auto& state = parameters.state; - const auto& evaluated = static_cast(*evaluatedProperties).evaluated; - if (layerGroup.empty()) { return; } + auto& context = parameters.context; + const auto& state = parameters.state; + const auto& evaluated = static_cast(*evaluatedProperties).evaluated; + #if !defined(NDEBUG) const auto label = layerGroup.getName() + "-update-uniforms"; const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 1f19253121b..848645c2b8d 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -91,6 +91,10 @@ class PolylineLayerTweaker : public LayerTweaker { propsUBO(properties) {} void execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) override { + if (layerGroup.empty()) { + return; + } + auto& context = parameters.context; auto& layerUniforms = layerGroup.mutableUniformBuffers(); layerUniforms.createOrUpdate(idLineEvaluatedPropsUBO, &propsUBO, context); diff --git a/src/mbgl/vulkan/buffer_resource.cpp b/src/mbgl/vulkan/buffer_resource.cpp index c86365bc29e..d2a3ee32ad4 100644 --- a/src/mbgl/vulkan/buffer_resource.cpp +++ b/src/mbgl/vulkan/buffer_resource.cpp @@ -62,7 +62,7 @@ BufferResource::BufferResource( const auto& align = deviceProps.limits.minUniformBufferOffsetAlignment; bufferWindowSize = (size + align - 1) & ~(align - 1); - // assert(bufferWindowSize != 0); + assert(bufferWindowSize != 0); totalSize = bufferWindowSize * backend.getMaxFrames(); } diff --git a/src/mbgl/vulkan/uniform_buffer.cpp b/src/mbgl/vulkan/uniform_buffer.cpp index 6a4ee1e0e16..f3574fab817 100644 --- a/src/mbgl/vulkan/uniform_buffer.cpp +++ b/src/mbgl/vulkan/uniform_buffer.cpp @@ -25,18 +25,18 @@ UniformBuffer::~UniformBuffer() { buffer.getContext().renderingStats().memUniformBuffers -= size; } -void UniformBuffer::update(const void* data, std::size_t size_) { - /*assert(size == size_); - if (size != size_ || size != buffer.getSizeInBytes()) { +void UniformBuffer::update(const void* data, std::size_t dataSize) { + assert(dataSize <= size); + if (dataSize > size || dataSize > buffer.getSizeInBytes()) { Log::Error( Event::General, - "Mismatched size given to UBO update, expected " + std::to_string(size) + ", got " + std::to_string(size_)); + "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + std::to_string(dataSize)); return; - }*/ + } buffer.getContext().renderingStats().numUniformUpdates++; - buffer.getContext().renderingStats().uniformUpdateBytes += size_; - buffer.update(data, size_, /*offset=*/0); + buffer.getContext().renderingStats().uniformUpdateBytes += dataSize; + buffer.update(data, dataSize, /*offset=*/0); } const std::shared_ptr& UniformBufferArray::set(const size_t id, From 7b43b50f334215f377b7b594c173c44c8ad95d47 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:33:01 +0000 Subject: [PATCH 13/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/mbgl/gl/uniform_buffer_gl.cpp | 6 +++--- src/mbgl/mtl/uniform_buffer.cpp | 6 +++--- src/mbgl/vulkan/uniform_buffer.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mbgl/gl/uniform_buffer_gl.cpp b/src/mbgl/gl/uniform_buffer_gl.cpp index 4f1a9a739af..7bc7d470d71 100644 --- a/src/mbgl/gl/uniform_buffer_gl.cpp +++ b/src/mbgl/gl/uniform_buffer_gl.cpp @@ -106,9 +106,9 @@ void UniformBufferGL::update(const void* data, std::size_t dataSize) { assert(isManagedAllocation ? dataSize <= managedBuffer.getContents().size() : dataSize <= size); if (dataSize > size || (isManagedAllocation && dataSize > managedBuffer.getContents().size())) { - Log::Error( - Event::General, - "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + std::to_string(dataSize)); + Log::Error(Event::General, + "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + + std::to_string(dataSize)); return; } diff --git a/src/mbgl/mtl/uniform_buffer.cpp b/src/mbgl/mtl/uniform_buffer.cpp index febf2235f36..f800323225a 100644 --- a/src/mbgl/mtl/uniform_buffer.cpp +++ b/src/mbgl/mtl/uniform_buffer.cpp @@ -28,9 +28,9 @@ UniformBuffer::~UniformBuffer() { void UniformBuffer::update(const void* data, std::size_t dataSize) { assert(dataSize <= size); if (dataSize > size || dataSize > buffer.getSizeInBytes()) { - Log::Error( - Event::General, - "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + std::to_string(dataSize)); + Log::Error(Event::General, + "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + + std::to_string(dataSize)); return; } diff --git a/src/mbgl/vulkan/uniform_buffer.cpp b/src/mbgl/vulkan/uniform_buffer.cpp index f3574fab817..ba9aef60e58 100644 --- a/src/mbgl/vulkan/uniform_buffer.cpp +++ b/src/mbgl/vulkan/uniform_buffer.cpp @@ -28,9 +28,9 @@ UniformBuffer::~UniformBuffer() { void UniformBuffer::update(const void* data, std::size_t dataSize) { assert(dataSize <= size); if (dataSize > size || dataSize > buffer.getSizeInBytes()) { - Log::Error( - Event::General, - "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + std::to_string(dataSize)); + Log::Error(Event::General, + "Mismatched size given to UBO update, expected max " + std::to_string(size) + ", got " + + std::to_string(dataSize)); return; }