mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Use DEPTH32FLOAT_STENCIL8 for metal support (#183)
* Switch to Depth32FloatStencil8 for support on metal. It seems to have better overal support. * Update formatting * Fix usage of wrong texture format * Make depth format configurable * Force install tools * Echo path * Change shell to msys2 for windows
This commit is contained in:
parent
79b956ec9b
commit
ec1ad07164
5
.github/actions/cargo-install/action.yml
vendored
5
.github/actions/cargo-install/action.yml
vendored
@ -9,9 +9,6 @@ inputs:
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Setup default toolchain
|
||||
shell: bash
|
||||
run: rustup show # Installs toolchain specified in rust-toolchain.toml
|
||||
- name: Install ${{ inputs.name }}
|
||||
shell: bash
|
||||
run: cargo binstall --no-confirm ${{ inputs.name }}
|
||||
run: cargo binstall --no-confirm --force ${{ inputs.name }}
|
||||
|
||||
3
.github/actions/setup-binstall/action.yml
vendored
3
.github/actions/setup-binstall/action.yml
vendored
@ -4,6 +4,9 @@ description: Setup binstall
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Setup default toolchain
|
||||
shell: bash
|
||||
run: rustup show # Installs toolchain specified in rust-toolchain.toml
|
||||
- name: Install binstall
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
6
.github/workflows/demo-windows.yml
vendored
6
.github/workflows/demo-windows.yml
vendored
@ -8,6 +8,9 @@ jobs:
|
||||
name: Build
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Switch shell to msys2
|
||||
run: echo "C:\msys64\usr\bin" >> $GITHUB_PATH
|
||||
shell: bash
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup binstall
|
||||
uses: ./.github/actions/setup-binstall
|
||||
@ -22,6 +25,9 @@ jobs:
|
||||
just stable-targets x86_64-pc-windows-msvc
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- uses: ilammy/msvc-dev-cmd@v1 # Provide access to lib.exe
|
||||
- name: Show PATH
|
||||
shell: bash
|
||||
run: echo $PATH
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: cargo build -p maplibre-demo --release --target x86_64-pc-windows-msvc
|
||||
|
||||
5
justfile
5
justfile
@ -125,6 +125,7 @@ xcodebuild-archive-fat EXISTING_ARCH EXISTING_PLATFORM ARCH: (xcodebuild-archive
|
||||
archive="{{BUILD_DIR}}/{{ARCH}}-apple-{{EXISTING_PLATFORM}}.xcarchive"
|
||||
existing_archive="{{BUILD_DIR}}/{{EXISTING_ARCH}}-apple-{{EXISTING_PLATFORM}}.xcarchive"
|
||||
fat_archive="{{BUILD_DIR}}/{{EXISTING_ARCH}}-{{ARCH}}-apple-{{EXISTING_PLATFORM}}.xcarchive"
|
||||
|
||||
cp -R "$existing_archive" "$fat_archive"
|
||||
inner="$archive/{{INNER_FRAMEWORK_PATH}}"
|
||||
existing_inner="$existing_archive/{{INNER_FRAMEWORK_PATH}}"
|
||||
@ -152,8 +153,8 @@ xcodebuild-xcframework: xcodebuild-clean (xcodebuild-archive "arm64" "iOS") (xc
|
||||
"arm64-x86_64,macOS"
|
||||
)
|
||||
framework_args=$(for i in "${tuples[@]}"; do IFS=","; set -- $i; echo -n "-framework \"{{BUILD_DIR}}/$1-apple-$2.xcarchive/{{INNER_FRAMEWORK_PATH}}\" "; done)
|
||||
echo "$framework_args"
|
||||
echo "$XC_FRAMEWORK_PATH"
|
||||
echo "framework_args: $framework_args"
|
||||
echo "XC_FRAMEWORK_PATH: $XC_FRAMEWORK_PATH"
|
||||
echo "$framework_args" | xargs xcodebuild -create-xcframework -output "$XC_FRAMEWORK_PATH"
|
||||
cat "$XC_FRAMEWORK_PATH/Info.plist"
|
||||
|
||||
|
||||
@ -1,31 +1,6 @@
|
||||
//! Handles platform specific code. Depending on the compilation target, different
|
||||
//! parts of this module are used.
|
||||
|
||||
// WebGPU
|
||||
#[cfg(all(target_arch = "wasm32", not(feature = "web-webgl")))]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8Unorm;
|
||||
|
||||
// WebGL
|
||||
#[cfg(all(target_arch = "wasm32", feature = "web-webgl"))]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
|
||||
|
||||
// Vulkan Android
|
||||
#[cfg(target_os = "android")]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
|
||||
|
||||
/// MacOS and iOS (Metal).
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
|
||||
/// For Vulkan/OpenGL
|
||||
#[cfg(not(any(
|
||||
target_os = "android",
|
||||
target_os = "macos",
|
||||
any(target_os = "macos", target_os = "ios"),
|
||||
target_arch = "wasm32"
|
||||
)))]
|
||||
pub const COLOR_TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod noweb;
|
||||
|
||||
@ -53,4 +28,4 @@ pub use noweb::run_multithreaded;
|
||||
///
|
||||
/// FIXME: This limit is enforced by WebGL. Actually this makes sense!
|
||||
/// FIXME: This can also be achieved by _pad attributes in shader_ffi.rs
|
||||
pub const MIN_BUFFER_SIZE: u64 = 32;
|
||||
pub const MIN_WEBGL_BUFFER_SIZE: u64 = 32;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
use std::{cmp, mem::size_of};
|
||||
|
||||
use crate::{platform::MIN_BUFFER_SIZE, render::shaders::ShaderGlobals};
|
||||
use crate::{platform::MIN_WEBGL_BUFFER_SIZE, render::shaders::ShaderGlobals};
|
||||
|
||||
pub struct Globals {
|
||||
pub uniform_buffer: wgpu::Buffer,
|
||||
@ -11,7 +11,8 @@ pub struct Globals {
|
||||
|
||||
impl Globals {
|
||||
pub fn from_device(device: &wgpu::Device, group: &wgpu::BindGroupLayout) -> Self {
|
||||
let globals_buffer_byte_size = cmp::max(MIN_BUFFER_SIZE, size_of::<ShaderGlobals>() as u64);
|
||||
let globals_buffer_byte_size =
|
||||
cmp::max(MIN_WEBGL_BUFFER_SIZE, size_of::<ShaderGlobals>() as u64);
|
||||
|
||||
let uniform_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("Globals ubo"),
|
||||
|
||||
@ -4,8 +4,6 @@ use std::borrow::Cow;
|
||||
|
||||
pub use wgpu::{Backends, Features, Limits, PowerPreference, TextureFormat};
|
||||
|
||||
use crate::platform::COLOR_TEXTURE_FORMAT;
|
||||
|
||||
/// Provides configuration for renderer initialization. Use [`Device::features`](crate::renderer::Device::features),
|
||||
/// [`Device::limits`](crate::renderer::Device::limits), and the [`WgpuAdapterInfo`](crate::render_resource::WgpuAdapterInfo)
|
||||
/// resource to get runtime information about the actual adapter, backend, features, and limits.
|
||||
@ -30,7 +28,7 @@ pub struct WgpuSettings {
|
||||
|
||||
impl Default for WgpuSettings {
|
||||
fn default() -> Self {
|
||||
let backends = Some(wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::all()));
|
||||
let backends = Some(wgpu::util::backend_bits_from_env().unwrap_or(Backends::all()));
|
||||
|
||||
let limits = if cfg!(feature = "web-webgl") {
|
||||
Limits {
|
||||
@ -54,11 +52,15 @@ impl Default for WgpuSettings {
|
||||
}
|
||||
};
|
||||
|
||||
let mut features = Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES;
|
||||
|
||||
features |= Features::DEPTH32FLOAT_STENCIL8;
|
||||
|
||||
Self {
|
||||
device_label: Default::default(),
|
||||
backends,
|
||||
power_preference: PowerPreference::HighPerformance,
|
||||
features: Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
|
||||
features,
|
||||
disabled_features: None,
|
||||
limits,
|
||||
constrained_limits: None,
|
||||
@ -99,17 +101,39 @@ impl Default for Msaa {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct RendererSettings {
|
||||
pub msaa: Msaa,
|
||||
pub texture_format: TextureFormat,
|
||||
pub depth_texture_format: TextureFormat,
|
||||
}
|
||||
|
||||
impl Default for RendererSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
msaa: Msaa::default(),
|
||||
texture_format: COLOR_TEXTURE_FORMAT,
|
||||
// WebGPU
|
||||
#[cfg(all(target_arch = "wasm32", not(feature = "web-webgl")))]
|
||||
texture_format: wgpu::TextureFormat::Bgra8Unorm,
|
||||
// WebGL
|
||||
#[cfg(all(target_arch = "wasm32", feature = "web-webgl"))]
|
||||
texture_format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||
// Vulkan Android
|
||||
#[cfg(target_os = "android")]
|
||||
texture_format: wgpu::TextureFormat::Rgba8Unorm,
|
||||
/// MacOS and iOS (Metal).
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
texture_format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||
/// For Vulkan/OpenGL
|
||||
#[cfg(not(any(
|
||||
target_os = "android",
|
||||
target_os = "macos",
|
||||
any(target_os = "macos", target_os = "ios"),
|
||||
target_arch = "wasm32"
|
||||
)))]
|
||||
texture_format: TextureFormat::Bgra8UnormSrgb,
|
||||
|
||||
depth_texture_format: TextureFormat::Depth32FloatStencil8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ impl Stage for ResourceStage {
|
||||
Texture::new(
|
||||
Some("depth texture"),
|
||||
device,
|
||||
wgpu::TextureFormat::Depth24PlusStencil8,
|
||||
settings.depth_texture_format,
|
||||
size.width(),
|
||||
size.height(),
|
||||
settings.msaa,
|
||||
@ -100,7 +100,7 @@ impl Stage for ResourceStage {
|
||||
};
|
||||
|
||||
let pipeline = TilePipeline::new(
|
||||
settings.msaa,
|
||||
*settings,
|
||||
tile_shader.describe_vertex(),
|
||||
tile_shader.describe_fragment(),
|
||||
true,
|
||||
@ -125,7 +125,7 @@ impl Stage for ResourceStage {
|
||||
};
|
||||
|
||||
TilePipeline::new(
|
||||
settings.msaa,
|
||||
*settings,
|
||||
mask_shader.describe_vertex(),
|
||||
mask_shader.describe_fragment(),
|
||||
false,
|
||||
|
||||
@ -3,12 +3,13 @@
|
||||
use std::cmp;
|
||||
|
||||
use crate::{
|
||||
platform::MIN_BUFFER_SIZE,
|
||||
platform::MIN_WEBGL_BUFFER_SIZE,
|
||||
render::{
|
||||
resource::{FragmentState, RenderPipeline, RenderPipelineDescriptor, VertexState},
|
||||
settings::Msaa,
|
||||
shaders::ShaderGlobals,
|
||||
},
|
||||
RendererSettings,
|
||||
};
|
||||
|
||||
pub struct TilePipeline {
|
||||
@ -16,7 +17,7 @@ pub struct TilePipeline {
|
||||
update_stencil: bool,
|
||||
debug_stencil: bool,
|
||||
wireframe: bool,
|
||||
msaa: Msaa,
|
||||
settings: RendererSettings,
|
||||
|
||||
vertex_state: VertexState,
|
||||
fragment_state: FragmentState,
|
||||
@ -24,7 +25,7 @@ pub struct TilePipeline {
|
||||
|
||||
impl TilePipeline {
|
||||
pub(crate) fn new(
|
||||
msaa: Msaa,
|
||||
settings: RendererSettings,
|
||||
vertex_state: VertexState,
|
||||
fragment_state: FragmentState,
|
||||
bind_globals: bool,
|
||||
@ -37,7 +38,7 @@ impl TilePipeline {
|
||||
update_stencil,
|
||||
debug_stencil,
|
||||
wireframe,
|
||||
msaa,
|
||||
settings,
|
||||
vertex_state,
|
||||
fragment_state,
|
||||
}
|
||||
@ -66,8 +67,10 @@ impl RenderPipeline for TilePipeline {
|
||||
}
|
||||
};
|
||||
|
||||
let globals_buffer_byte_size =
|
||||
cmp::max(MIN_BUFFER_SIZE, std::mem::size_of::<ShaderGlobals>() as u64);
|
||||
let globals_buffer_byte_size = cmp::max(
|
||||
MIN_WEBGL_BUFFER_SIZE,
|
||||
std::mem::size_of::<ShaderGlobals>() as u64,
|
||||
);
|
||||
|
||||
RenderPipelineDescriptor {
|
||||
label: None,
|
||||
@ -103,7 +106,7 @@ impl RenderPipeline for TilePipeline {
|
||||
unclipped_depth: false,
|
||||
},
|
||||
depth_stencil: Some(wgpu::DepthStencilState {
|
||||
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
||||
format: self.settings.depth_texture_format,
|
||||
depth_write_enabled: !self.update_stencil,
|
||||
depth_compare: wgpu::CompareFunction::Greater,
|
||||
stencil: wgpu::StencilState {
|
||||
@ -115,7 +118,7 @@ impl RenderPipeline for TilePipeline {
|
||||
bias: wgpu::DepthBiasState::default(),
|
||||
}),
|
||||
multisample: wgpu::MultisampleState {
|
||||
count: self.msaa.samples,
|
||||
count: self.settings.msaa.samples,
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user