mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 14:31:08 +01:00
Merge #907
907: Implement OpenGL Backend For Unix Platforms r=kvark a=zicklag **Connections** Requires: https://github.com/gfx-rs/gfx/pull/3340 ( merged ) Should be merged first: https://github.com/gfx-rs/wgpu/pull/910 Works towards: https://github.com/gfx-rs/wgpu/issues/450 **Description** Integrates the GFX GL backend for Unix platforms **Testing** Runs the basic cube and triangle examples for wgpu-rs, but not without rendering artifacts on the cube. <!-- Non-trivial functional changes would need to be tested through: - [wgpu-rs](https://github.com/gfx-rs/wgpu-rs) - test the examples. - [wgpu-native](https://github.com/gfx-rs/wgpu-native/) - check the generated C header for sanity. Ideally, a PR needs to link to the draft PRs in these projects with relevant modifications. See https://github.com/gfx-rs/wgpu/pull/666 for an example. If you can add a unit/integration test here in `wgpu`, that would be best. --> Co-authored-by: Zicklag <zicklag@katharostech.com>
This commit is contained in:
7 files changed
+666
-88
No files matched your search
Generated
+600
-78
File diff suppressed because it is too large.
Load diff
@@ -48,6 +48,9 @@ path = "../wgpu-types"
|
||||
package = "wgpu-types"
|
||||
version = "0.6"
|
||||
|
||||
[target.'cfg(all(unix, not(target_os = "ios")))'.dependencies]
|
||||
gfx-backend-gl = { version = "0.6" }
|
||||
|
||||
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
|
||||
gfx-backend-metal = { version = "0.6" }
|
||||
gfx-backend-vulkan = { version = "0.6.4", optional = true }
|
||||
@@ -64,4 +67,4 @@ gfx-backend-vulkan = { version = "0.6.4" }
|
||||
loom = "0.3"
|
||||
|
||||
[build-dependencies]
|
||||
cfg_aliases = "0.1"
|
||||
cfg_aliases = "0.1"
|
||||
+4
-2
@@ -6,13 +6,15 @@ fn main() {
|
||||
// Setup cfg aliases
|
||||
cfg_aliases::cfg_aliases! {
|
||||
// Vendors/systems
|
||||
apple: { any(target_os = "ios", target_os = "macos") },
|
||||
ios: { target_os = "ios" },
|
||||
macos: { target_os = "macos" },
|
||||
apple: { any(ios, macos) },
|
||||
|
||||
// Backends
|
||||
vulkan: { any(windows, all(unix, not(apple)), feature = "gfx-backend-vulkan") },
|
||||
metal: { apple },
|
||||
dx12: { windows },
|
||||
dx11: { windows },
|
||||
gl: { unix },
|
||||
gl: { all(unix, not(ios)) },
|
||||
}
|
||||
}
|
||||
@@ -1736,15 +1736,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
None
|
||||
};
|
||||
|
||||
let actual_border = desc
|
||||
let actual_border: hal::image::PackedColor = desc
|
||||
.border_color
|
||||
.map(|c| match c {
|
||||
wgt::SamplerBorderColor::TransparentBlack => [0.0, 0.0, 0.0, 0.0],
|
||||
wgt::SamplerBorderColor::OpaqueBlack => [0.0, 0.0, 0.0, 1.0],
|
||||
wgt::SamplerBorderColor::OpaqueWhite => [1.0, 1.0, 1.0, 1.0],
|
||||
wgt::SamplerBorderColor::TransparentBlack => {
|
||||
[0., 0., 0., 0.].into()
|
||||
}
|
||||
wgt::SamplerBorderColor::OpaqueBlack => [0., 0., 0., 1.].into(),
|
||||
wgt::SamplerBorderColor::OpaqueWhite => [1., 1., 1., 1.].into(),
|
||||
})
|
||||
.map(hal::image::PackedColor::from)
|
||||
.unwrap_or(hal::image::PackedColor(0));
|
||||
.unwrap_or([0., 0., 0., 0.].into());
|
||||
|
||||
let info = hal::image::SamplerDesc {
|
||||
min_filter: conv::map_filter(desc.min_filter),
|
||||
|
||||
@@ -670,6 +670,8 @@ pub struct Hubs<F: GlobalIdentityHandlerFactory> {
|
||||
dx12: Hub<backend::Dx12, F>,
|
||||
#[cfg(dx11)]
|
||||
dx11: Hub<backend::Dx11, F>,
|
||||
#[cfg(gl)]
|
||||
gl: Hub<backend::Gl, F>,
|
||||
}
|
||||
|
||||
impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
|
||||
@@ -683,6 +685,8 @@ impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
|
||||
dx12: Hub::new(factory),
|
||||
#[cfg(dx11)]
|
||||
dx11: Hub::new(factory),
|
||||
#[cfg(gl)]
|
||||
gl: Hub::new(factory),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -734,6 +738,10 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
|
||||
{
|
||||
self.hubs.dx11.clear(&mut *surface_guard);
|
||||
}
|
||||
#[cfg(gl)]
|
||||
{
|
||||
self.hubs.gl.clear(&mut *surface_guard);
|
||||
}
|
||||
|
||||
// destroy surfaces
|
||||
for element in surface_guard.map.drain(..) {
|
||||
@@ -795,6 +803,17 @@ impl GfxBackend for backend::Dx11 {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(gl)]
|
||||
impl GfxBackend for backend::Gl {
|
||||
const VARIANT: Backend = Backend::Gl;
|
||||
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self, G> {
|
||||
&global.hubs.gl
|
||||
}
|
||||
fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface {
|
||||
surface.gl.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn _test_send_sync(global: &Global<IdentityManagerFactory>) {
|
||||
fn test_internal<T: Send + Sync>(_: T) {}
|
||||
|
||||
@@ -38,6 +38,8 @@ pub struct Instance {
|
||||
pub dx12: Option<gfx_backend_dx12::Instance>,
|
||||
#[cfg(dx11)]
|
||||
pub dx11: Option<gfx_backend_dx11::Instance>,
|
||||
#[cfg(gl)]
|
||||
pub gl: Option<gfx_backend_gl::Instance>,
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
@@ -59,6 +61,8 @@ impl Instance {
|
||||
dx12: map((Backend::Dx12, gfx_backend_dx12::Instance::create)),
|
||||
#[cfg(dx11)]
|
||||
dx11: map((Backend::Dx11, gfx_backend_dx11::Instance::create)),
|
||||
#[cfg(gl)]
|
||||
gl: map((Backend::Gl, gfx_backend_gl::Instance::create)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,6 +85,8 @@ impl Instance {
|
||||
map((surface.dx12, &mut self.dx12)),
|
||||
#[cfg(dx11)]
|
||||
map((surface.dx11, &mut self.dx11)),
|
||||
#[cfg(gl)]
|
||||
map((surface.gl, &mut self.gl)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,6 +103,8 @@ pub struct Surface {
|
||||
pub dx12: Option<GfxSurface<backend::Dx12>>,
|
||||
#[cfg(dx11)]
|
||||
pub dx11: Option<GfxSurface<backend::Dx11>>,
|
||||
#[cfg(gl)]
|
||||
pub gl: Option<GfxSurface<backend::Gl>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -340,7 +348,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let map = |inst| {
|
||||
inst
|
||||
.as_ref()
|
||||
.and_then(|inst| inst.create_surface(handle).ok())
|
||||
.and_then(|inst| inst.create_surface(handle).map_err(|e| {
|
||||
tracing::warn!("Error: {:?}", e);
|
||||
}).ok())
|
||||
};
|
||||
|
||||
Surface {
|
||||
@@ -352,6 +362,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
dx12: map(&self.instance.dx12),
|
||||
#[cfg(dx11)]
|
||||
dx11: map(&self.instance.dx11),
|
||||
#[cfg(gl)]
|
||||
gl: map(&self.instance.gl),
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -395,6 +407,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
map((&instance.dx12, Backend::Dx12, "Dx12", backend::Dx12::hub)),
|
||||
#[cfg(dx11)]
|
||||
map((&instance.dx11, Backend::Dx11, "Dx11", backend::Dx11::hub)),
|
||||
#[cfg(gl)]
|
||||
map((&instance.gl, Backend::Gl, "GL", backend::Gl::hub)),
|
||||
}
|
||||
|
||||
adapters
|
||||
@@ -424,6 +438,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let mut id_metal = inputs.find(Backend::Metal);
|
||||
let mut id_dx12 = inputs.find(Backend::Dx12);
|
||||
let mut id_dx11 = inputs.find(Backend::Dx11);
|
||||
let mut id_gl = inputs.find(Backend::Gl);
|
||||
|
||||
backends_map! {
|
||||
let map = |(instance_backend, id_backend, surface_backend)| {
|
||||
@@ -475,6 +490,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
surface_dx11
|
||||
}));
|
||||
#[cfg(gl)]
|
||||
let adapters_gl = map((&instance.gl, &id_gl, {
|
||||
fn surface_gl(surf: &Surface) -> Option<&GfxSurface<backend::Gl>> {
|
||||
surf.gl.as_ref()
|
||||
}
|
||||
surface_gl
|
||||
}));
|
||||
}
|
||||
|
||||
if device_types.is_empty() {
|
||||
@@ -530,6 +552,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
map(("Dx12", &mut id_dx12, adapters_dx12, backend::Dx12::hub)),
|
||||
#[cfg(dx11)]
|
||||
map(("Dx11", &mut id_dx11, adapters_dx11, backend::Dx11::hub)),
|
||||
#[cfg(gl)]
|
||||
map(("GL", &mut id_dx11, adapters_gl, backend::Gl::hub)),
|
||||
}
|
||||
|
||||
let _ = (
|
||||
@@ -538,6 +562,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
id_metal.take(),
|
||||
id_dx12.take(),
|
||||
id_dx11.take(),
|
||||
id_gl.take(),
|
||||
);
|
||||
tracing::warn!("Some adapters are present, but enumerating them failed!");
|
||||
Err(RequestAdapterError::NotFound)
|
||||
|
||||
@@ -19,6 +19,8 @@ pub mod backend {
|
||||
pub use gfx_backend_dx11::Backend as Dx11;
|
||||
#[cfg(dx12)]
|
||||
pub use gfx_backend_dx12::Backend as Dx12;
|
||||
#[cfg(gl)]
|
||||
pub use gfx_backend_gl::Backend as Gl;
|
||||
#[cfg(metal)]
|
||||
pub use gfx_backend_metal::Backend as Metal;
|
||||
#[cfg(vulkan)]
|
||||
@@ -203,6 +205,8 @@ struct PrivateFeatures {
|
||||
#[macro_export]
|
||||
macro_rules! gfx_select {
|
||||
($id:expr => $global:ident.$method:ident( $($param:expr),* )) => {
|
||||
// Note: For some reason the cfg aliases defined in build.rs don't succesfully apply in this
|
||||
// macro so we must specify their equivalents manually
|
||||
match $id.backend() {
|
||||
#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))]
|
||||
wgt::Backend::Vulkan => $global.$method::<$crate::backend::Vulkan>( $($param),* ),
|
||||
@@ -212,6 +216,8 @@ macro_rules! gfx_select {
|
||||
wgt::Backend::Dx12 => $global.$method::<$crate::backend::Dx12>( $($param),* ),
|
||||
#[cfg(windows)]
|
||||
wgt::Backend::Dx11 => $global.$method::<$crate::backend::Dx11>( $($param),* ),
|
||||
#[cfg(all(unix, not(target_os = "ios")))]
|
||||
wgt::Backend::Gl => $global.$method::<$crate::backend::Gl>( $($param),+ ),
|
||||
_ => unreachable!()
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user