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:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- name: Setup default toolchain
|
|
||||||
shell: bash
|
|
||||||
run: rustup show # Installs toolchain specified in rust-toolchain.toml
|
|
||||||
- name: Install ${{ inputs.name }}
|
- name: Install ${{ inputs.name }}
|
||||||
shell: bash
|
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:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
|
- name: Setup default toolchain
|
||||||
|
shell: bash
|
||||||
|
run: rustup show # Installs toolchain specified in rust-toolchain.toml
|
||||||
- name: Install binstall
|
- name: Install binstall
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
6
.github/workflows/demo-windows.yml
vendored
6
.github/workflows/demo-windows.yml
vendored
@ -8,6 +8,9 @@ jobs:
|
|||||||
name: Build
|
name: Build
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
steps:
|
steps:
|
||||||
|
- name: Switch shell to msys2
|
||||||
|
run: echo "C:\msys64\usr\bin" >> $GITHUB_PATH
|
||||||
|
shell: bash
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup binstall
|
- name: Setup binstall
|
||||||
uses: ./.github/actions/setup-binstall
|
uses: ./.github/actions/setup-binstall
|
||||||
@ -22,6 +25,9 @@ jobs:
|
|||||||
just stable-targets x86_64-pc-windows-msvc
|
just stable-targets x86_64-pc-windows-msvc
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- uses: ilammy/msvc-dev-cmd@v1 # Provide access to lib.exe
|
- uses: ilammy/msvc-dev-cmd@v1 # Provide access to lib.exe
|
||||||
|
- name: Show PATH
|
||||||
|
shell: bash
|
||||||
|
run: echo $PATH
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cargo build -p maplibre-demo --release --target x86_64-pc-windows-msvc
|
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"
|
archive="{{BUILD_DIR}}/{{ARCH}}-apple-{{EXISTING_PLATFORM}}.xcarchive"
|
||||||
existing_archive="{{BUILD_DIR}}/{{EXISTING_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"
|
fat_archive="{{BUILD_DIR}}/{{EXISTING_ARCH}}-{{ARCH}}-apple-{{EXISTING_PLATFORM}}.xcarchive"
|
||||||
|
|
||||||
cp -R "$existing_archive" "$fat_archive"
|
cp -R "$existing_archive" "$fat_archive"
|
||||||
inner="$archive/{{INNER_FRAMEWORK_PATH}}"
|
inner="$archive/{{INNER_FRAMEWORK_PATH}}"
|
||||||
existing_inner="$existing_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"
|
"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)
|
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 "framework_args: $framework_args"
|
||||||
echo "$XC_FRAMEWORK_PATH"
|
echo "XC_FRAMEWORK_PATH: $XC_FRAMEWORK_PATH"
|
||||||
echo "$framework_args" | xargs xcodebuild -create-xcframework -output "$XC_FRAMEWORK_PATH"
|
echo "$framework_args" | xargs xcodebuild -create-xcframework -output "$XC_FRAMEWORK_PATH"
|
||||||
cat "$XC_FRAMEWORK_PATH/Info.plist"
|
cat "$XC_FRAMEWORK_PATH/Info.plist"
|
||||||
|
|
||||||
|
|||||||
@ -1,31 +1,6 @@
|
|||||||
//! Handles platform specific code. Depending on the compilation target, different
|
//! Handles platform specific code. Depending on the compilation target, different
|
||||||
//! parts of this module are used.
|
//! 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"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod noweb;
|
mod noweb;
|
||||||
|
|
||||||
@ -53,4 +28,4 @@ pub use noweb::run_multithreaded;
|
|||||||
///
|
///
|
||||||
/// FIXME: This limit is enforced by WebGL. Actually this makes sense!
|
/// FIXME: This limit is enforced by WebGL. Actually this makes sense!
|
||||||
/// FIXME: This can also be achieved by _pad attributes in shader_ffi.rs
|
/// 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 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 struct Globals {
|
||||||
pub uniform_buffer: wgpu::Buffer,
|
pub uniform_buffer: wgpu::Buffer,
|
||||||
@ -11,7 +11,8 @@ pub struct Globals {
|
|||||||
|
|
||||||
impl Globals {
|
impl Globals {
|
||||||
pub fn from_device(device: &wgpu::Device, group: &wgpu::BindGroupLayout) -> Self {
|
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 {
|
let uniform_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
label: Some("Globals ubo"),
|
label: Some("Globals ubo"),
|
||||||
|
|||||||
@ -4,8 +4,6 @@ use std::borrow::Cow;
|
|||||||
|
|
||||||
pub use wgpu::{Backends, Features, Limits, PowerPreference, TextureFormat};
|
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),
|
/// 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)
|
/// [`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.
|
/// resource to get runtime information about the actual adapter, backend, features, and limits.
|
||||||
@ -30,7 +28,7 @@ pub struct WgpuSettings {
|
|||||||
|
|
||||||
impl Default for WgpuSettings {
|
impl Default for WgpuSettings {
|
||||||
fn default() -> Self {
|
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") {
|
let limits = if cfg!(feature = "web-webgl") {
|
||||||
Limits {
|
Limits {
|
||||||
@ -54,11 +52,15 @@ impl Default for WgpuSettings {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut features = Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES;
|
||||||
|
|
||||||
|
features |= Features::DEPTH32FLOAT_STENCIL8;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
device_label: Default::default(),
|
device_label: Default::default(),
|
||||||
backends,
|
backends,
|
||||||
power_preference: PowerPreference::HighPerformance,
|
power_preference: PowerPreference::HighPerformance,
|
||||||
features: Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES,
|
features,
|
||||||
disabled_features: None,
|
disabled_features: None,
|
||||||
limits,
|
limits,
|
||||||
constrained_limits: None,
|
constrained_limits: None,
|
||||||
@ -99,17 +101,39 @@ impl Default for Msaa {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct RendererSettings {
|
pub struct RendererSettings {
|
||||||
pub msaa: Msaa,
|
pub msaa: Msaa,
|
||||||
pub texture_format: TextureFormat,
|
pub texture_format: TextureFormat,
|
||||||
|
pub depth_texture_format: TextureFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RendererSettings {
|
impl Default for RendererSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
msaa: Msaa::default(),
|
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(
|
Texture::new(
|
||||||
Some("depth texture"),
|
Some("depth texture"),
|
||||||
device,
|
device,
|
||||||
wgpu::TextureFormat::Depth24PlusStencil8,
|
settings.depth_texture_format,
|
||||||
size.width(),
|
size.width(),
|
||||||
size.height(),
|
size.height(),
|
||||||
settings.msaa,
|
settings.msaa,
|
||||||
@ -100,7 +100,7 @@ impl Stage for ResourceStage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let pipeline = TilePipeline::new(
|
let pipeline = TilePipeline::new(
|
||||||
settings.msaa,
|
*settings,
|
||||||
tile_shader.describe_vertex(),
|
tile_shader.describe_vertex(),
|
||||||
tile_shader.describe_fragment(),
|
tile_shader.describe_fragment(),
|
||||||
true,
|
true,
|
||||||
@ -125,7 +125,7 @@ impl Stage for ResourceStage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TilePipeline::new(
|
TilePipeline::new(
|
||||||
settings.msaa,
|
*settings,
|
||||||
mask_shader.describe_vertex(),
|
mask_shader.describe_vertex(),
|
||||||
mask_shader.describe_fragment(),
|
mask_shader.describe_fragment(),
|
||||||
false,
|
false,
|
||||||
|
|||||||
@ -3,12 +3,13 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
platform::MIN_BUFFER_SIZE,
|
platform::MIN_WEBGL_BUFFER_SIZE,
|
||||||
render::{
|
render::{
|
||||||
resource::{FragmentState, RenderPipeline, RenderPipelineDescriptor, VertexState},
|
resource::{FragmentState, RenderPipeline, RenderPipelineDescriptor, VertexState},
|
||||||
settings::Msaa,
|
settings::Msaa,
|
||||||
shaders::ShaderGlobals,
|
shaders::ShaderGlobals,
|
||||||
},
|
},
|
||||||
|
RendererSettings,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct TilePipeline {
|
pub struct TilePipeline {
|
||||||
@ -16,7 +17,7 @@ pub struct TilePipeline {
|
|||||||
update_stencil: bool,
|
update_stencil: bool,
|
||||||
debug_stencil: bool,
|
debug_stencil: bool,
|
||||||
wireframe: bool,
|
wireframe: bool,
|
||||||
msaa: Msaa,
|
settings: RendererSettings,
|
||||||
|
|
||||||
vertex_state: VertexState,
|
vertex_state: VertexState,
|
||||||
fragment_state: FragmentState,
|
fragment_state: FragmentState,
|
||||||
@ -24,7 +25,7 @@ pub struct TilePipeline {
|
|||||||
|
|
||||||
impl TilePipeline {
|
impl TilePipeline {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
msaa: Msaa,
|
settings: RendererSettings,
|
||||||
vertex_state: VertexState,
|
vertex_state: VertexState,
|
||||||
fragment_state: FragmentState,
|
fragment_state: FragmentState,
|
||||||
bind_globals: bool,
|
bind_globals: bool,
|
||||||
@ -37,7 +38,7 @@ impl TilePipeline {
|
|||||||
update_stencil,
|
update_stencil,
|
||||||
debug_stencil,
|
debug_stencil,
|
||||||
wireframe,
|
wireframe,
|
||||||
msaa,
|
settings,
|
||||||
vertex_state,
|
vertex_state,
|
||||||
fragment_state,
|
fragment_state,
|
||||||
}
|
}
|
||||||
@ -66,8 +67,10 @@ impl RenderPipeline for TilePipeline {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let globals_buffer_byte_size =
|
let globals_buffer_byte_size = cmp::max(
|
||||||
cmp::max(MIN_BUFFER_SIZE, std::mem::size_of::<ShaderGlobals>() as u64);
|
MIN_WEBGL_BUFFER_SIZE,
|
||||||
|
std::mem::size_of::<ShaderGlobals>() as u64,
|
||||||
|
);
|
||||||
|
|
||||||
RenderPipelineDescriptor {
|
RenderPipelineDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
@ -103,7 +106,7 @@ impl RenderPipeline for TilePipeline {
|
|||||||
unclipped_depth: false,
|
unclipped_depth: false,
|
||||||
},
|
},
|
||||||
depth_stencil: Some(wgpu::DepthStencilState {
|
depth_stencil: Some(wgpu::DepthStencilState {
|
||||||
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
format: self.settings.depth_texture_format,
|
||||||
depth_write_enabled: !self.update_stencil,
|
depth_write_enabled: !self.update_stencil,
|
||||||
depth_compare: wgpu::CompareFunction::Greater,
|
depth_compare: wgpu::CompareFunction::Greater,
|
||||||
stencil: wgpu::StencilState {
|
stencil: wgpu::StencilState {
|
||||||
@ -115,7 +118,7 @@ impl RenderPipeline for TilePipeline {
|
|||||||
bias: wgpu::DepthBiasState::default(),
|
bias: wgpu::DepthBiasState::default(),
|
||||||
}),
|
}),
|
||||||
multisample: wgpu::MultisampleState {
|
multisample: wgpu::MultisampleState {
|
||||||
count: self.msaa.samples,
|
count: self.settings.msaa.samples,
|
||||||
mask: !0,
|
mask: !0,
|
||||||
alpha_to_coverage_enabled: false,
|
alpha_to_coverage_enabled: false,
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user