Instance plumbing

This commit is contained in:
Dzmitry Malyshau committed 2021-06-08 11:46:53 -04:00
1 parent ff2a3e84fc
commit a421c1c8b6
17 files changed
+589 -197

No files matched your search

Generated
+26
View File
@@ -892,6 +892,20 @@ dependencies = [
"autocfg",
]
[[package]]
name = "metal"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c12e48c737ee9a55e8bb2352bcde588f79ae308d3529ee888f7cc0f469b5777"
dependencies = [
"bitflags",
"block",
"cocoa-foundation",
"foreign-types",
"log",
"objc",
]
[[package]]
name = "miniz_oxide"
version = "0.3.7"
@@ -1155,6 +1169,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
"objc_exception",
]
[[package]]
name = "objc_exception"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4"
dependencies = [
"cc",
]
[[package]]
@@ -1858,6 +1882,7 @@ dependencies = [
"wasm-bindgen-futures",
"web-sys",
"wgpu-core",
"wgpu-hal",
"wgpu-types",
"winit",
]
@@ -1890,6 +1915,7 @@ name = "wgpu-hal"
version = "0.1.0"
dependencies = [
"bitflags",
"metal",
"naga",
"raw-window-handle",
"smallvec",
+40 -38
View File
@@ -39,12 +39,12 @@ impl<I: Clone + Debug + wgc::id::TypedId> wgc::hub::IdentityHandlerFactory<I>
impl wgc::hub::GlobalIdentityHandlerFactory for IdentityPassThroughFactory {}
pub trait GlobalPlay {
fn encode_commands<B: wgc::hub::HalApi>(
fn encode_commands<A: wgc::hub::HalApi>(
&self,
encoder: wgc::id::CommandEncoderId,
commands: Vec<trace::Command>,
) -> wgc::id::CommandBufferId;
fn process<B: wgc::hub::HalApi>(
fn process<A: wgc::hub::HalApi>(
&self,
device: wgc::id::DeviceId,
action: trace::Action,
@@ -54,7 +54,7 @@ pub trait GlobalPlay {
}
impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
fn encode_commands<B: wgc::hub::HalApi>(
fn encode_commands<A: wgc::hub::HalApi>(
&self,
encoder: wgc::id::CommandEncoderId,
commands: Vec<trace::Command>,
@@ -139,48 +139,50 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
cmd_buf
}
fn process<B: wgc::hub::HalApi>(
fn process<A: wgc::hub::HalApi>(
&self,
device: wgc::id::DeviceId,
action: trace::Action,
dir: &Path,
comb_manager: &mut wgc::hub::IdentityManager,
) {
use wgc::device::trace::Action as A;
use wgc::device::trace::Action;
log::info!("action {:?}", action);
//TODO: find a way to force ID perishing without excessive `maintain()` calls.
match action {
A::Init { .. } => panic!("Unexpected Action::Init: has to be the first action only"),
A::CreateSwapChain { .. } | A::PresentSwapChain(_) => {
Action::Init { .. } => {
panic!("Unexpected Action::Init: has to be the first action only")
}
Action::CreateSwapChain { .. } | Action::PresentSwapChain(_) => {
panic!("Unexpected SwapChain action: winit feature is not enabled")
}
A::CreateBuffer(id, desc) => {
Action::CreateBuffer(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_buffer::<A>(device, &desc, id);
if let Some(e) = error {
panic!("{:?}", e);
}
}
A::FreeBuffer(id) => {
Action::FreeBuffer(id) => {
self.buffer_destroy::<A>(id).unwrap();
}
A::DestroyBuffer(id) => {
Action::DestroyBuffer(id) => {
self.buffer_drop::<A>(id, true);
}
A::CreateTexture(id, desc) => {
Action::CreateTexture(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_texture::<A>(device, &desc, id);
if let Some(e) = error {
panic!("{:?}", e);
}
}
A::FreeTexture(id) => {
Action::FreeTexture(id) => {
self.texture_destroy::<A>(id).unwrap();
}
A::DestroyTexture(id) => {
Action::DestroyTexture(id) => {
self.texture_drop::<A>(id, true);
}
A::CreateTextureView {
Action::CreateTextureView {
id,
parent_id,
desc,
@@ -191,56 +193,56 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
panic!("{:?}", e);
}
}
A::DestroyTextureView(id) => {
Action::DestroyTextureView(id) => {
self.texture_view_drop::<A>(id, true).unwrap();
}
A::CreateSampler(id, desc) => {
Action::CreateSampler(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_sampler::<A>(device, &desc, id);
if let Some(e) = error {
panic!("{:?}", e);
}
}
A::DestroySampler(id) => {
Action::DestroySampler(id) => {
self.sampler_drop::<A>(id);
}
A::GetSwapChainTexture { id, parent_id } => {
Action::GetSwapChainTexture { id, parent_id } => {
self.device_maintain_ids::<A>(device).unwrap();
self.swap_chain_get_current_texture_view::<A>(parent_id, id)
.unwrap()
.view_id
.unwrap();
}
A::CreateBindGroupLayout(id, desc) => {
Action::CreateBindGroupLayout(id, desc) => {
let (_, error) = self.device_create_bind_group_layout::<A>(device, &desc, id);
if let Some(e) = error {
panic!("{:?}", e);
}
}
A::DestroyBindGroupLayout(id) => {
Action::DestroyBindGroupLayout(id) => {
self.bind_group_layout_drop::<A>(id);
}
A::CreatePipelineLayout(id, desc) => {
Action::CreatePipelineLayout(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_pipeline_layout::<A>(device, &desc, id);
if let Some(e) = error {
panic!("{:?}", e);
}
}
A::DestroyPipelineLayout(id) => {
Action::DestroyPipelineLayout(id) => {
self.pipeline_layout_drop::<A>(id);
}
A::CreateBindGroup(id, desc) => {
Action::CreateBindGroup(id, desc) => {
self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_bind_group::<A>(device, &desc, id);
if let Some(e) = error {
panic!("{:?}", e);
}
}
A::DestroyBindGroup(id) => {
Action::DestroyBindGroup(id) => {
self.bind_group_drop::<A>(id);
}
A::CreateShaderModule { id, desc, data } => {
Action::CreateShaderModule { id, desc, data } => {
let source = if data.ends_with(".wgsl") {
let code = fs::read_to_string(dir.join(data)).unwrap();
wgc::pipeline::ShaderModuleSource::Wgsl(Cow::Owned(code))
@@ -258,10 +260,10 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
panic!("{:?}", e);
}
}
A::DestroyShaderModule(id) => {
Action::DestroyShaderModule(id) => {
self.shader_module_drop::<A>(id);
}
A::CreateComputePipeline {
Action::CreateComputePipeline {
id,
desc,
implicit_context,
@@ -280,10 +282,10 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
panic!("{:?}", e);
}
}
A::DestroyComputePipeline(id) => {
Action::DestroyComputePipeline(id) => {
self.compute_pipeline_drop::<A>(id);
}
A::CreateRenderPipeline {
Action::CreateRenderPipeline {
id,
desc,
implicit_context,
@@ -302,10 +304,10 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
panic!("{:?}", e);
}
}
A::DestroyRenderPipeline(id) => {
Action::DestroyRenderPipeline(id) => {
self.render_pipeline_drop::<A>(id);
}
A::CreateRenderBundle { id, desc, base } => {
Action::CreateRenderBundle { id, desc, base } => {
let bundle =
wgc::command::RenderBundleEncoder::new(&desc, device, Some(base)).unwrap();
let (_, error) = self.render_bundle_encoder_finish::<A>(
@@ -317,20 +319,20 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
panic!("{:?}", e);
}
}
A::DestroyRenderBundle(id) => {
Action::DestroyRenderBundle(id) => {
self.render_bundle_drop::<A>(id);
}
A::CreateQuerySet { id, desc } => {
Action::CreateQuerySet { id, desc } => {
self.device_maintain_ids::<A>(device).unwrap();
let (_, error) = self.device_create_query_set::<A>(device, &desc, id);
if let Some(e) = error {
panic!("{:?}", e);
}
}
A::DestroyQuerySet(id) => {
Action::DestroyQuerySet(id) => {
self.query_set_drop::<A>(id);
}
A::WriteBuffer {
Action::WriteBuffer {
id,
data,
range,
@@ -347,7 +349,7 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
.unwrap();
}
}
A::WriteTexture {
Action::WriteTexture {
to,
data,
layout,
@@ -357,10 +359,10 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
self.queue_write_texture::<A>(device, &to, &bin, &layout, &size)
.unwrap();
}
A::Submit(_index, ref commands) if commands.is_empty() => {
Action::Submit(_index, ref commands) if commands.is_empty() => {
self.queue_submit::<A>(device, &[]).unwrap();
}
A::Submit(_index, commands) => {
Action::Submit(_index, commands) => {
let (encoder, error) = self.device_create_command_encoder::<A>(
device,
&wgt::CommandEncoderDescriptor { label: None },
+4
View File
@@ -49,6 +49,10 @@ path = "../wgpu-hal"
package = "wgpu-hal"
version = "0.1"
[target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies]
hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["metal"] }
#Note: could also enable "vulkan" for Vulkan Portability
[dev-dependencies]
loom = "0.3"
+4 -4
View File
@@ -11,10 +11,10 @@ fn main() {
unix_wo_apple: {all(unix, not(apple))},
// Backends
vulkan: { all(not(wasm), any(windows, unix_wo_apple)) },
vulkan: { all(false, not(wasm), any(windows, unix_wo_apple)) },
metal: { all(not(wasm), apple) },
dx12: { all(not(wasm), windows) },
dx11: { all(not(wasm), windows) },
gl: { any(wasm, unix_wo_apple) },
dx12: { all(false, not(wasm), windows) },
dx11: { all(false, not(wasm), windows) },
gl: { all(false, any(wasm, unix_wo_apple)) },
}
}
+4 -7
View File
@@ -4103,27 +4103,24 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn poll_all_devices(&self, force_wait: bool) -> Result<(), WaitIdleError> {
//use crate::backend;
let mut callbacks = Vec::new();
/*
#[cfg(vulkan)]
{
self.poll_devices::<backend::Vulkan>(force_wait, &mut callbacks)?;
self.poll_devices::<hal::api::Vulkan>(force_wait, &mut callbacks)?;
}
#[cfg(metal)]
{
self.poll_devices::<backend::Metal>(force_wait, &mut callbacks)?;
self.poll_devices::<hal::api::Metal>(force_wait, &mut callbacks)?;
}
#[cfg(dx12)]
{
self.poll_devices::<backend::Dx12>(force_wait, &mut callbacks)?;
self.poll_devices::<hal::api::Dx12>(force_wait, &mut callbacks)?;
}
#[cfg(dx11)]
{
self.poll_devices::<backend::Dx11>(force_wait, &mut callbacks)?;
self.poll_devices::<hal::api::Dx11>(force_wait, &mut callbacks)?;
}
*/
fire_map_callbacks(callbacks);
+6 -14
View File
@@ -718,26 +718,22 @@ impl<A: HalApi, F: GlobalIdentityHandlerFactory> Hub<A, F> {
}
}
#[derive(Debug)]
pub struct Hubs<F: GlobalIdentityHandlerFactory> {
/*
#[cfg(vulkan)]
vulkan: Hub<backend::Vulkan, F>,
#[cfg(metal)]
metal: Hub<backend::Metal, F>,
metal: Hub<hal::api::Metal, F>,
#[cfg(dx12)]
dx12: Hub<backend::Dx12, F>,
#[cfg(dx11)]
dx11: Hub<backend::Dx11, F>,
#[cfg(gl)]
gl: Hub<backend::Gl, F>,*/
marker: PhantomData<F>,
gl: Hub<backend::Gl, F>,
}
impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
fn new(factory: &F) -> Self {
Self {
/*
#[cfg(vulkan)]
vulkan: Hub::new(factory),
#[cfg(metal)]
@@ -748,13 +744,10 @@ impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
dx11: Hub::new(factory),
#[cfg(gl)]
gl: Hub::new(factory),
*/
marker: PhantomData,
}
}
}
#[derive(Debug)]
pub struct Global<G: GlobalIdentityHandlerFactory> {
pub instance: Instance,
pub surfaces: Registry<Surface, id::SurfaceId, G>,
@@ -765,7 +758,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn new(name: &str, factory: G, backends: wgt::BackendBit) -> Self {
profiling::scope!("new", "Global");
Self {
instance: Instance::new(name, 1, backends),
instance: Instance::new(name, backends),
surfaces: Registry::without_backend(&factory, "Surface"),
hubs: Hubs::new(&factory),
}
@@ -786,7 +779,6 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
let mut surface_guard = self.surfaces.data.write();
// destroy hubs before the instance gets dropped
/*
#[cfg(vulkan)]
{
self.hubs.vulkan.clear(&mut *surface_guard, true);
@@ -807,7 +799,6 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
{
self.hubs.gl.clear(&mut *surface_guard, true);
}
*/
// destroy surfaces
for element in surface_guard.map.drain(..) {
@@ -834,10 +825,10 @@ impl HalApi for backend::Vulkan {
fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface {
surface.vulkan.as_mut().unwrap()
}
}
}*/
#[cfg(metal)]
impl HalApi for backend::Metal {
impl HalApi for hal::api::Metal {
const VARIANT: Backend = Backend::Metal;
fn hub<G: GlobalIdentityHandlerFactory>(global: &Global<G>) -> &Hub<Self, G> {
&global.hubs.metal
@@ -847,6 +838,7 @@ impl HalApi for backend::Metal {
}
}
/*
#[cfg(dx12)]
impl HalApi for backend::Dx12 {
const VARIANT: Backend = Backend::Dx12;
+1 -1
View File
@@ -8,7 +8,7 @@ use wgt::Backend;
const BACKEND_BITS: usize = 3;
const EPOCH_MASK: u32 = (1 << (32 - BACKEND_BITS)) - 1;
type Dummy = crate::backend::Empty;
type Dummy = hal::api::Empty;
#[repr(transparent)]
#[cfg_attr(feature = "trace", derive(serde::Serialize), serde(into = "SerialId"))]
+69 -86
View File
@@ -11,50 +11,49 @@ use crate::{
use wgt::{Backend, BackendBit, PowerPreference, BIND_BUFFER_ALIGNMENT};
use hal::Adapter as _;
use hal::{Adapter as _, Instance as _};
use thiserror::Error;
pub type RequestAdapterOptions = wgt::RequestAdapterOptions<SurfaceId>;
type HalInstance<A> = <A as hal::Api>::Instance;
type HalSurface<A> = <A as hal::Api>::Surface;
#[derive(Debug)]
pub struct Instance {
/*
#[cfg(vulkan)]
pub vulkan: Option<gfx_backend_vulkan::Instance>,
#[cfg(metal)]
pub metal: Option<gfx_backend_metal::Instance>,
#[cfg(dx12)]
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>,
*/}
#[allow(dead_code)]
name: String,
#[cfg(vulkan)]
pub vulkan: Option<gfx_backend_vulkan::Instance>,
#[cfg(metal)]
pub metal: Option<HalInstance<hal::api::Metal>>,
#[cfg(dx12)]
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 {
pub fn new(name: &str, version: u32, backends: BackendBit) -> Self {
backends_map! {
let map = |(backend, backend_create)| {
if backends.contains(backend.into()) {
backend_create(name, version).ok()
} else {
None
}
};
Self {
/*
#[cfg(vulkan)]
vulkan: map((Backend::Vulkan, gfx_backend_vulkan::Instance::create)),
#[cfg(metal)]
metal: map((Backend::Metal, gfx_backend_metal::Instance::create)),
#[cfg(dx12)]
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)),
*/
pub fn new(name: &str, backends: BackendBit) -> Self {
let map = |backend: Backend| unsafe {
if backends.contains(backend.into()) {
hal::Instance::init().ok()
} else {
None
}
};
Self {
name: name.to_string(),
#[cfg(vulkan)]
vulkan: map((Backend::Vulkan)),
#[cfg(metal)]
metal: map(Backend::Metal),
#[cfg(dx12)]
dx12: map((Backend::Dx12)),
#[cfg(dx11)]
dx11: map((Backend::Dx11)),
#[cfg(gl)]
gl: map((Backend::Gl)),
}
}
@@ -68,7 +67,6 @@ impl Instance {
}
};
/*
#[cfg(vulkan)]
map((surface.vulkan, &self.vulkan)),
#[cfg(metal)]
@@ -79,27 +77,22 @@ impl Instance {
map((surface.dx11, &self.dx11)),
#[cfg(gl)]
map((surface.gl, &self.gl)),
*/
}
}
}
type HalSurface<A> = <A as hal::Api>::Surface;
#[derive(Debug)]
pub struct Surface {
/*
#[cfg(vulkan)]
pub vulkan: Option<HalSurface<backend::Vulkan>>,
#[cfg(metal)]
pub metal: Option<HalSurface<backend::Metal>>,
#[cfg(dx12)]
pub dx12: Option<HalSurface<backend::Dx12>>,
#[cfg(dx11)]
pub dx11: Option<HalSurface<backend::Dx11>>,
#[cfg(gl)]
pub gl: Option<HalSurface<backend::Gl>>,
*/}
#[cfg(vulkan)]
pub vulkan: Option<HalSurface<hal::api::Vulkan>>,
#[cfg(metal)]
pub metal: Option<HalSurface<hal::api::Metal>>,
#[cfg(dx12)]
pub dx12: Option<HalSurface<hal::api::Dx12>>,
#[cfg(dx11)]
pub dx11: Option<HalSurface<hal::api::Dx11>>,
#[cfg(gl)]
pub gl: Option<HalSurface<hal::api::Gl>>,
}
impl crate::hub::Resource for Surface {
const TYPE: &'static str = "Surface";
@@ -352,7 +345,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
Surface {
/*
#[cfg(vulkan)]
vulkan: map(&self.instance.vulkan),
#[cfg(metal)]
@@ -363,7 +355,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
dx11: map(&self.instance.dx11),
#[cfg(gl)]
gl: map(&self.instance.gl),
*/
}
}
};
@@ -373,6 +364,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
id.0
}
/*TODO: raw CALayer handling
#[cfg(metal)]
pub fn instance_create_surface_metal(
&self,
@@ -382,18 +374,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
profiling::scope!("create_surface_metal", "Instance");
let surface = Surface {
/*
metal: self.instance.metal.as_ref().map(|inst| {
// we don't want to link to metal-rs for this
#[allow(clippy::transmute_ptr_to_ref)]
inst.create_surface_from_layer(unsafe { std::mem::transmute(layer) })
}),*/
}),
};
let mut token = Token::root();
let id = self.surfaces.prepare(id_in).assign(surface, &mut token);
id.0
}
}*/
pub fn surface_drop(&self, id: SurfaceId) {
profiling::scope!("drop", "Surface");
@@ -410,11 +401,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut adapters = Vec::new();
backends_map! {
let map = |(instance_field, backend, backend_info, backend_hub)| {
let map = |(instance_field, backend, backend_info)| {
if let Some(ref inst) = *instance_field {
let hub = backend_hub(self);
let hub = HalApi::hub(self);
if let Some(id_backend) = inputs.find(backend) {
for raw in inst.enumerate_adapters() {
for raw in unsafe {inst.enumerate_adapters()} {
let adapter = Adapter::new(raw);
log::info!("Adapter {} {:?}", backend_info, adapter.raw.info);
let id = hub.adapters
@@ -426,18 +417,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
};
/*
#[cfg(vulkan)]
map((&instance.vulkan, Backend::Vulkan, "Vulkan", backend::Vulkan::hub)),
map((&instance.vulkan, Backend::Vulkan, "Vulkan")),
#[cfg(metal)]
map((&instance.metal, Backend::Metal, "Metal", backend::Metal::hub)),
map((&instance.metal, Backend::Metal, "Metal")),
#[cfg(dx12)]
map((&instance.dx12, Backend::Dx12, "Dx12", backend::Dx12::hub)),
map((&instance.dx12, Backend::Dx12, "Dx12")),
#[cfg(dx11)]
map((&instance.dx11, Backend::Dx11, "Dx11", backend::Dx11::hub)),
map((&instance.dx11, Backend::Dx11, "Dx11")),
#[cfg(gl)]
map((&instance.gl, Backend::Gl, "GL", backend::Gl::hub)),
*/
map((&instance.gl, Backend::Gl, "GL")),
}
adapters
@@ -473,13 +462,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let map = |(instance_backend, id_backend, surface_backend)| {
match *instance_backend {
Some(ref inst) if id_backend.is_some() => {
let mut adapters = inst.enumerate_adapters();
let mut adapters = unsafe { inst.enumerate_adapters() };
if let Some(surface_backend) = compatible_surface.and_then(surface_backend) {
adapters.retain(|a| {
a.queue_families
.iter()
.find(|qf| qf.queue_type().supports_graphics())
.map_or(false, |qf| surface_backend.supports_queue_family(qf))
adapters.retain(|exposed| unsafe {
exposed.adapter.surface_capabilities(surface_backend).is_some()
});
}
device_types.extend(adapters.iter().map(|ad| ad.info.device_type));
@@ -491,7 +477,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
// NB: The internal function definitions are a workaround for Rust
// being weird with lifetimes for closure literals...
/*
#[cfg(vulkan)]
let adapters_vk = map((&instance.vulkan, &id_vulkan, {
fn surface_vulkan(surf: &Surface) -> Option<&HalSurface<backend::Vulkan>> {
@@ -501,7 +486,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}));
#[cfg(metal)]
let adapters_mtl = map((&instance.metal, &id_metal, {
fn surface_metal(surf: &Surface) -> Option<&HalSurface<backend::Metal>> {
fn surface_metal(surf: &Surface) -> Option<&HalSurface<hal::api::Metal>> {
surf.metal.as_ref()
}
surface_metal
@@ -526,7 +511,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
surf.gl.as_ref()
}
surface_gl
}));*/
}));
}
if device_types.is_empty() {
@@ -564,11 +549,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut selected = preferred_gpu.unwrap_or(0);
backends_map! {
let map = |(info_adapter, id_backend, mut adapters_backend, backend_hub)| {
let map = |(info_adapter, id_backend, mut adapters_backend)| {
if selected < adapters_backend.len() {
let adapter = Adapter::new(adapters_backend.swap_remove(selected));
log::info!("Adapter {} {:?}", info_adapter, adapter.raw.info);
let id = backend_hub(self).adapters
let id = HalApi::hub(self).adapters
.prepare(id_backend.take().unwrap())
.assign(adapter, &mut token);
return Ok(id.0);
@@ -576,18 +561,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
selected -= adapters_backend.len();
};
/*
#[cfg(vulkan)]
map(("Vulkan", &mut id_vulkan, adapters_vk, backend::Vulkan::hub)),
map(("Vulkan", &mut id_vulkan, adapters_vk)),
#[cfg(metal)]
map(("Metal", &mut id_metal, adapters_mtl, backend::Metal::hub)),
map(("Metal", &mut id_metal, adapters_mtl)),
#[cfg(dx12)]
map(("Dx12", &mut id_dx12, adapters_dx12, backend::Dx12::hub)),
map(("Dx12", &mut id_dx12, adapters_dx12)),
#[cfg(dx11)]
map(("Dx11", &mut id_dx11, adapters_dx11, backend::Dx11::hub)),
map(("Dx11", &mut id_dx11, adapters_dx11)),
#[cfg(gl)]
map(("GL", &mut id_gl, adapters_gl, backend::Gl::hub)),
*/
map(("GL", &mut id_gl, adapters_gl)),
}
let _ = (
+6 -20
View File
@@ -31,22 +31,6 @@
#[macro_use]
mod macros;
pub mod backend {
pub use hal::empty::Api as Empty;
/*
#[cfg(dx11)]
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)]
pub use gfx_backend_vulkan::Backend as Vulkan;
*/
}
pub mod binding_model;
pub mod command;
mod conv;
@@ -61,6 +45,8 @@ pub mod swap_chain;
mod track;
mod validation;
pub use hal::api;
#[cfg(test)]
use loom::sync::atomic;
#[cfg(not(test))]
@@ -257,11 +243,11 @@ macro_rules! gfx_select {
// 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(all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")))]
wgt::Backend::Vulkan => $global.$method::<$crate::backend::Vulkan>( $($param),* ),
//#[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios"), not(target_os = "macos")))]
//wgt::Backend::Vulkan => $global.$method::<$crate::backend::Vulkan>( $($param),* ),
#[cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))]
wgt::Backend::Metal => $global.$method::<$crate::backend::Metal>( $($param),* ),
wgt::Backend::Metal => $global.$method::<$crate::api::Metal>( $($param),* ),
/*
#[cfg(all(not(target_arch = "wasm32"), windows))]
wgt::Backend::Dx12 => $global.$method::<$crate::backend::Dx12>( $($param),* ),
#[cfg(all(not(target_arch = "wasm32"), windows))]
+5 -1
View File
@@ -7,11 +7,12 @@ description = "WebGPU hardware abstraction layer"
homepage = "https://github.com/gfx-rs/wgpu"
repository = "https://github.com/gfx-rs/wgpu"
keywords = ["graphics"]
license = "MPL-2.0"
license = "MIT OR Apache-2.0"
[lib]
[features]
metal = ["mtl"]
[dependencies]
bitflags = "1.0"
@@ -20,6 +21,9 @@ smallvec = "1"
thiserror = "1"
wgt = { package = "wgpu-types", path = "../wgpu-types" }
# backends
mtl = { package = "metal", version = "0.22", optional = true }
[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
tag = "gfx-25"
+5 -1
View File
@@ -37,12 +37,16 @@ impl crate::Api for Api {
}
impl crate::Instance<Api> for Context {
unsafe fn init() -> Result<Self, crate::InstanceError> {
Ok(Context)
}
unsafe fn create_surface(
&self,
rwh: &impl raw_window_handle::HasRawWindowHandle,
) -> Result<Context, crate::UnsupportedWindow> {
) -> Result<Context, crate::InstanceError> {
Ok(Context)
}
unsafe fn destroy_surface(&self, surface: Context) {}
unsafe fn enumerate_adapters(&self) -> Vec<crate::ExposedAdapter<Api>> {
Vec::new()
}
+14 -4
View File
@@ -37,6 +37,14 @@
)]
pub mod empty;
#[cfg(feature = "metal")]
mod metal;
pub mod api {
pub use super::empty::Api as Empty;
#[cfg(feature = "metal")]
pub use super::metal::Api as Metal;
}
use std::{
borrow::{Borrow, Cow},
@@ -97,8 +105,8 @@ pub enum SurfaceError {
}
#[derive(Clone, Debug, PartialEq, Error)]
#[error("Window handle is not supported")]
pub struct UnsupportedWindow;
#[error("Not supported")]
pub struct InstanceError;
pub trait Api: Clone + Sized {
type Instance: Instance<Self>;
@@ -124,11 +132,13 @@ pub trait Api: Clone + Sized {
type ComputePipeline;
}
pub trait Instance<A: Api> {
pub trait Instance<A: Api>: Sized {
unsafe fn init() -> Result<Self, InstanceError>;
unsafe fn create_surface(
&self,
rwh: &impl raw_window_handle::HasRawWindowHandle,
) -> Result<A::Surface, UnsupportedWindow>;
) -> Result<A::Surface, InstanceError>;
unsafe fn destroy_surface(&self, surface: A::Surface);
unsafe fn enumerate_adapters(&self) -> Vec<ExposedAdapter<A>>;
}
+379
View File
@@ -0,0 +1,379 @@
#![allow(unused_variables)]
use std::ops::Range;
#[derive(Clone)]
pub struct Api;
pub struct Context;
pub struct Encoder;
#[derive(Debug)]
pub struct Resource;
type DeviceResult<T> = Result<T, crate::DeviceError>;
impl crate::Api for Api {
type Instance = Context;
type Surface = Context;
type Adapter = Context;
type Queue = Context;
type Device = Context;
type CommandBuffer = Encoder;
type Buffer = Resource;
type Texture = Resource;
type SurfaceTexture = Resource;
type TextureView = Resource;
type Sampler = Resource;
type QuerySet = Resource;
type Fence = Resource;
type BindGroupLayout = Resource;
type BindGroup = Resource;
type PipelineLayout = Resource;
type ShaderModule = Resource;
type RenderPipeline = Resource;
type ComputePipeline = Resource;
}
impl crate::Instance<Api> for Context {
unsafe fn init() -> Result<Self, crate::InstanceError> {
Ok(Context)
}
unsafe fn create_surface(
&self,
rwh: &impl raw_window_handle::HasRawWindowHandle,
) -> Result<Context, crate::InstanceError> {
Ok(Context)
}
unsafe fn destroy_surface(&self, surface: Context) {}
unsafe fn enumerate_adapters(&self) -> Vec<crate::ExposedAdapter<Api>> {
Vec::new()
}
}
impl crate::Surface<Api> for Context {
unsafe fn configure(
&mut self,
device: &Context,
config: &crate::SurfaceConfiguration,
) -> Result<(), crate::SurfaceError> {
Ok(())
}
unsafe fn unconfigure(&mut self, device: &Context) {}
unsafe fn acquire_texture(
&mut self,
timeout_ms: u32,
) -> Result<Option<crate::AcquiredSurfaceTexture<Api>>, crate::SurfaceError> {
Ok(None)
}
unsafe fn discard_texture(&mut self, texture: Resource) {}
}
impl crate::Adapter<Api> for Context {
unsafe fn open(&self, features: wgt::Features) -> DeviceResult<crate::OpenDevice<Api>> {
Err(crate::DeviceError::Lost)
}
unsafe fn close(&self, device: Context) {}
unsafe fn texture_format_capabilities(
&self,
format: wgt::TextureFormat,
) -> crate::TextureFormatCapability {
crate::TextureFormatCapability::empty()
}
unsafe fn surface_capabilities(&self, surface: &Context) -> Option<crate::SurfaceCapabilities> {
None
}
}
impl crate::Queue<Api> for Context {
unsafe fn submit<I>(
&mut self,
command_buffers: I,
signal_fence: Option<(&Resource, crate::FenceValue)>,
) {
}
unsafe fn present(
&mut self,
surface: &mut Context,
texture: Resource,
) -> Result<(), crate::SurfaceError> {
Ok(())
}
}
impl crate::Device<Api> for Context {
unsafe fn create_buffer(&self, desc: &crate::BufferDescriptor) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_buffer(&self, buffer: Resource) {}
unsafe fn map_buffer(
&self,
buffer: &Resource,
range: crate::MemoryRange,
) -> DeviceResult<std::ptr::NonNull<u8>> {
Err(crate::DeviceError::Lost)
}
unsafe fn unmap_buffer(&self, buffer: &Resource) -> DeviceResult<()> {
Ok(())
}
unsafe fn flush_mapped_ranges<I>(&self, buffer: &Resource, ranges: I) {}
unsafe fn invalidate_mapped_ranges<I>(&self, buffer: &Resource, ranges: I) {}
unsafe fn create_texture(&self, desc: &crate::TextureDescriptor) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_texture(&self, texture: Resource) {}
unsafe fn create_texture_view(
&self,
texture: &Resource,
desc: &crate::TextureViewDescriptor,
) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_texture_view(&self, view: Resource) {}
unsafe fn create_sampler(&self, desc: &crate::SamplerDescriptor) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_sampler(&self, sampler: Resource) {}
unsafe fn create_command_buffer(
&self,
desc: &crate::CommandBufferDescriptor,
) -> DeviceResult<Encoder> {
Ok(Encoder)
}
unsafe fn destroy_command_buffer(&self, cmd_buf: Encoder) {}
unsafe fn create_bind_group_layout(
&self,
desc: &crate::BindGroupLayoutDescriptor,
) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_bind_group_layout(&self, bg_layout: Resource) {}
unsafe fn create_pipeline_layout(
&self,
desc: &crate::PipelineLayoutDescriptor<Api>,
) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_pipeline_layout(&self, pipeline_layout: Resource) {}
unsafe fn create_bind_group(
&self,
desc: &crate::BindGroupDescriptor<Api>,
) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_bind_group(&self, group: Resource) {}
unsafe fn create_shader_module(
&self,
desc: &crate::ShaderModuleDescriptor,
shader: crate::NagaShader,
) -> Result<Resource, (crate::ShaderError, crate::NagaShader)> {
Ok(Resource)
}
unsafe fn destroy_shader_module(&self, module: Resource) {}
unsafe fn create_render_pipeline(
&self,
desc: &crate::RenderPipelineDescriptor<Api>,
) -> Result<Resource, crate::PipelineError> {
Ok(Resource)
}
unsafe fn destroy_render_pipeline(&self, pipeline: Resource) {}
unsafe fn create_compute_pipeline(
&self,
desc: &crate::ComputePipelineDescriptor<Api>,
) -> Result<Resource, crate::PipelineError> {
Ok(Resource)
}
unsafe fn destroy_compute_pipeline(&self, pipeline: Resource) {}
unsafe fn create_query_set(&self, desc: &wgt::QuerySetDescriptor) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_query_set(&self, set: Resource) {}
unsafe fn create_fence(&self) -> DeviceResult<Resource> {
Ok(Resource)
}
unsafe fn destroy_fence(&self, fence: Resource) {}
unsafe fn get_fence_value(&self, fence: &Resource) -> DeviceResult<crate::FenceValue> {
Ok(0)
}
unsafe fn wait(
&self,
fence: &Resource,
value: crate::FenceValue,
timeout_ms: u32,
) -> DeviceResult<bool> {
Ok(true)
}
unsafe fn start_capture(&self) -> bool {
false
}
unsafe fn stop_capture(&self) {}
}
impl crate::CommandBuffer<Api> for Encoder {
unsafe fn finish(&mut self) {}
unsafe fn transition_buffers<'a, T>(&mut self, barriers: T)
where
T: Iterator<Item = crate::BufferBarrier<'a, Api>>,
{
}
unsafe fn transition_textures<'a, T>(&mut self, barriers: T)
where
T: Iterator<Item = crate::TextureBarrier<'a, Api>>,
{
}
unsafe fn fill_buffer(&mut self, buffer: &Resource, range: crate::MemoryRange, value: u8) {}
unsafe fn copy_buffer_to_buffer<T>(&mut self, src: &Resource, dst: &Resource, regions: T)
where
T: Iterator<Item = crate::BufferCopy>,
{
}
/// Note: `dst` current usage has to be `TextureUse::COPY_DST`.
unsafe fn copy_texture_to_texture<T>(
&mut self,
src: &Resource,
src_usage: crate::TextureUse,
dst: &Resource,
regions: T,
) {
}
/// Note: `dst` current usage has to be `TextureUse::COPY_DST`.
unsafe fn copy_buffer_to_texture<T>(&mut self, src: &Resource, dst: &Resource, regions: T) {}
unsafe fn copy_texture_to_buffer<T>(
&mut self,
src: &Resource,
src_usage: crate::TextureUse,
dst: &Resource,
regions: T,
) {
}
unsafe fn begin_query(&mut self, set: &Resource, index: u32) {}
unsafe fn end_query(&mut self, set: &Resource, index: u32) {}
unsafe fn write_timestamp(&mut self, set: &Resource, index: u32) {}
unsafe fn reset_queries(&mut self, set: &Resource, range: Range<u32>) {}
unsafe fn copy_query_results(
&mut self,
set: &Resource,
range: Range<u32>,
buffer: &Resource,
offset: wgt::BufferAddress,
) {
}
// render
unsafe fn begin_render_pass(&mut self, desc: &crate::RenderPassDescriptor<Api>) {}
unsafe fn end_render_pass(&mut self) {}
unsafe fn set_bind_group(
&mut self,
layout: &Resource,
index: u32,
group: &Resource,
dynamic_offsets: &[u32],
) {
}
unsafe fn set_push_constants(
&mut self,
layout: &Resource,
stages: wgt::ShaderStage,
offset: u32,
data: &[u32],
) {
}
unsafe fn insert_debug_marker(&mut self, label: &str) {}
unsafe fn begin_debug_marker(&mut self, group_label: &str) {}
unsafe fn end_debug_marker(&mut self) {}
unsafe fn set_render_pipeline(&mut self, pipeline: &Resource) {}
unsafe fn set_index_buffer<'a>(
&mut self,
binding: crate::BufferBinding<'a, Api>,
format: wgt::IndexFormat,
) {
}
unsafe fn set_vertex_buffer<'a>(&mut self, index: u32, binding: crate::BufferBinding<'a, Api>) {
}
unsafe fn set_viewport(&mut self, rect: &crate::Rect<f32>, depth_range: Range<f32>) {}
unsafe fn set_scissor_rect(&mut self, rect: &crate::Rect<u32>) {}
unsafe fn set_stencil_reference(&mut self, value: u32) {}
unsafe fn set_blend_constants(&mut self, color: &wgt::Color) {}
unsafe fn draw(
&mut self,
start_vertex: u32,
vertex_count: u32,
start_instance: u32,
instance_count: u32,
) {
}
unsafe fn draw_indexed(
&mut self,
start_index: u32,
index_count: u32,
base_vertex: i32,
start_instance: u32,
instance_count: u32,
) {
}
unsafe fn draw_indirect(
&mut self,
buffer: &Resource,
offset: wgt::BufferAddress,
draw_count: u32,
) {
}
unsafe fn draw_indexed_indirect(
&mut self,
buffer: &Resource,
offset: wgt::BufferAddress,
draw_count: u32,
) {
}
unsafe fn draw_indirect_count(
&mut self,
buffer: &Resource,
offset: wgt::BufferAddress,
count_buffer: &Resource,
count_offset: wgt::BufferAddress,
max_count: u32,
) {
}
unsafe fn draw_indexed_indirect_count(
&mut self,
buffer: &Resource,
offset: wgt::BufferAddress,
count_buffer: &Resource,
count_offset: wgt::BufferAddress,
max_count: u32,
) {
}
// compute
unsafe fn begin_compute_pass(&mut self) {}
unsafe fn end_compute_pass(&mut self) {}
unsafe fn set_compute_pipeline(&mut self, pipeline: &Resource) {}
unsafe fn dispatch(&mut self, count: [u32; 3]) {}
unsafe fn dispatch_indirect(&mut self, buffer: &Resource, offset: wgt::BufferAddress) {}
}
+4
View File
@@ -36,6 +36,10 @@ optional = true
package = "wgpu-types"
path = "../wgpu-types"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.hal]
package = "wgpu-hal"
path = "../wgpu-hal"
[dependencies]
arrayvec = "0.5"
log = "0.4"
+11 -10
View File
@@ -50,6 +50,7 @@ impl Context {
}))
}
/*TODO: raw surface
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub unsafe fn create_surface_from_core_animation_layer(
self: &Arc<Self>,
@@ -60,7 +61,7 @@ impl Context {
context: Arc::clone(self),
id,
}
}
}*/
fn handle_error(
&self,
@@ -540,6 +541,7 @@ fn map_texture_copy_view(view: crate::ImageCopyTexture) -> wgc::command::ImageCo
texture: view.texture.id.id,
mip_level: view.mip_level,
origin: view.origin,
aspect: view.aspect,
}
}
@@ -806,7 +808,6 @@ impl crate::Context for Context {
let global = &self.0;
let descriptor = wgc::pipeline::ShaderModuleDescriptor {
label: desc.label.map(Borrowed),
flags: desc.flags,
};
let source = match desc.source {
ShaderSource::SpirV(ref spv) => wgc::pipeline::ShaderModuleSource::SpirV(Borrowed(spv)),
@@ -951,20 +952,20 @@ impl crate::Context for Context {
device: &Self::DeviceId,
desc: &PipelineLayoutDescriptor,
) -> Self::PipelineLayoutId {
// Limit is always less or equal to wgc::MAX_BIND_GROUPS, so this is always right
// Limit is always less or equal to hal::MAX_BIND_GROUPS, so this is always right
// Guards following ArrayVec
assert!(
desc.bind_group_layouts.len() <= wgc::MAX_BIND_GROUPS,
desc.bind_group_layouts.len() <= hal::MAX_BIND_GROUPS,
"Bind group layout count {} exceeds device bind group limit {}",
desc.bind_group_layouts.len(),
wgc::MAX_BIND_GROUPS
hal::MAX_BIND_GROUPS
);
let temp_layouts = desc
.bind_group_layouts
.iter()
.map(|bgl| bgl.id)
.collect::<ArrayVec<[_; wgc::MAX_BIND_GROUPS]>>();
.collect::<ArrayVec<[_; hal::MAX_BIND_GROUPS]>>();
let descriptor = wgc::binding_model::PipelineLayoutDescriptor {
label: desc.label.map(Borrowed),
bind_group_layouts: Borrowed(&temp_layouts),
@@ -996,7 +997,7 @@ impl crate::Context for Context {
) -> Self::RenderPipelineId {
use wgc::pipeline as pipe;
let vertex_buffers: ArrayVec<[_; wgc::device::MAX_VERTEX_BUFFERS]> = desc
let vertex_buffers: ArrayVec<[_; hal::MAX_VERTEX_BUFFERS]> = desc
.vertex
.buffers
.iter()
@@ -1011,7 +1012,7 @@ impl crate::Context for Context {
Some(_) => None,
None => Some(wgc::device::ImplicitPipelineIds {
root_id: PhantomData,
group_ids: &[PhantomData; wgc::MAX_BIND_GROUPS],
group_ids: &[PhantomData; hal::MAX_BIND_GROUPS],
}),
};
let descriptor = pipe::RenderPipelineDescriptor {
@@ -1071,7 +1072,7 @@ impl crate::Context for Context {
Some(_) => None,
None => Some(wgc::device::ImplicitPipelineIds {
root_id: PhantomData,
group_ids: &[PhantomData; wgc::MAX_BIND_GROUPS],
group_ids: &[PhantomData; hal::MAX_BIND_GROUPS],
}),
};
let descriptor = pipe::ComputePipelineDescriptor {
@@ -1731,7 +1732,7 @@ impl crate::Context for Context {
resolve_target: ca.resolve_target.map(|rt| rt.id),
channel: map_pass_channel(Some(&ca.ops)),
})
.collect::<ArrayVec<[_; wgc::device::MAX_COLOR_TARGETS]>>();
.collect::<ArrayVec<[_; hal::MAX_COLOR_TARGETS]>>();
let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| {
wgc::command::RenderPassDepthStencilAttachment {
+8 -9
View File
@@ -33,12 +33,12 @@ pub use wgt::{
ImageDataLayout, IndexFormat, InputStepMode, Limits, MultisampleState, Origin3d,
PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState,
PrimitiveTopology, PushConstantRange, QuerySetDescriptor, QueryType, SamplerBorderColor,
ShaderFlags, ShaderLocation, ShaderModel, ShaderStage, StencilFaceState, StencilOperation,
StencilState, StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, TextureAspect,
TextureDimension, TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures,
TextureSampleType, TextureUsage, TextureViewDimension, VertexAttribute, VertexFormat,
BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT,
PUSH_CONSTANT_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
ShaderLocation, ShaderModel, ShaderStage, StencilFaceState, StencilOperation, StencilState,
StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, TextureAspect, TextureDimension,
TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType,
TextureUsage, TextureViewDimension, VertexAttribute, VertexFormat, BIND_BUFFER_ALIGNMENT,
COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT,
QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
};
use backend::{BufferMappedRange, Context as C};
@@ -750,8 +750,6 @@ pub struct ShaderModuleDescriptor<'a> {
pub label: Label<'a>,
/// Source code for the shader.
pub source: ShaderSource<'a>,
/// Shader handling flags.
pub flags: ShaderFlags,
}
/// Handle to a pipeline layout.
@@ -1420,6 +1418,7 @@ impl Instance {
}
}
/*TODO: raw CAL surface
/// Creates a surface from `CoreAnimationLayer`.
///
/// # Safety
@@ -1431,7 +1430,7 @@ impl Instance {
layer: *mut std::ffi::c_void,
) -> Surface {
self.context.create_surface_from_core_animation_layer(layer)
}
}*/
/// Polls all devices.
/// If `force_wait` is true and this is not running on the web,
+3 -2
View File
@@ -1,4 +1,4 @@
use std::{convert::TryFrom, num::NonZeroU32};
use std::num::NonZeroU32;
/// Describes a [Buffer](crate::Buffer) when allocating.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
@@ -106,7 +106,7 @@ impl DeviceExt for crate::Device {
let height_blocks = mip_physical.height / format_info.block_dimensions.1 as u32;
let bytes_per_row = width_blocks * format_info.block_size as u32;
let data_size = bytes_per_row * height_blocks * mip_extent.depth_or_array_layers;
let data_size = bytes_per_row * height_blocks * mip_size.depth_or_array_layers;
let end_offset = binary_offset + data_size as usize;
@@ -119,6 +119,7 @@ impl DeviceExt for crate::Device {
y: 0,
z: layer,
},
aspect: wgt::TextureAspect::All,
},
&data[binary_offset..end_offset],
crate::ImageDataLayout {