Switch gfx-hal to 0.6

This commit is contained in:
Dzmitry Malyshau 2020-08-17 01:07:03 -04:00
parent f7ec6cc1fe
commit d1da6d8106
12 changed files with 286 additions and 212 deletions

135
Cargo.lock generated
View File

@ -90,12 +90,9 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "base64"
version = "0.10.1"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
dependencies = [
"byteorder",
]
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "bitflags"
@ -164,6 +161,15 @@ dependencies = [
"bitflags",
]
[[package]]
name = "cloudabi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467"
dependencies = [
"bitflags",
]
[[package]]
name = "cocoa"
version = "0.20.1"
@ -396,9 +402,9 @@ dependencies = [
[[package]]
name = "gfx-auxil"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67bdbf8e8d6883c70e5a0d7379ad8ab3ac95127a3761306b36122d8f1c177a8e"
checksum = "6311ee3cc7a3b4c8ae94c4513cd2cbe888ec37990cf0ffa672bd275391b12eb1"
dependencies = [
"fxhash",
"gfx-hal",
@ -407,16 +413,16 @@ dependencies = [
[[package]]
name = "gfx-backend-dx11"
version = "0.5.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92de0ddc0fde1a89b2a0e92dcc6bbb554bd34af0135e53a28d5ef064611094a4"
checksum = "de0a460b6458f3857af43064c687b1a010fe1f1b2e8c68fcd1d5db7206fa0809"
dependencies = [
"bitflags",
"gfx-auxil",
"gfx-hal",
"libloading 0.5.2",
"libloading 0.6.2",
"log",
"parking_lot",
"parking_lot 0.11.0",
"range-alloc",
"raw-window-handle",
"smallvec",
@ -427,9 +433,9 @@ dependencies = [
[[package]]
name = "gfx-backend-dx12"
version = "0.5.8"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05218b5c94539f22ac7d6feb4b2482431b89f6cc897132494701ac48619218d7"
checksum = "815ea94b924aa3a98e52ba3f090564c2186c7ef33fc0afa2f6b72314935c8798"
dependencies = [
"bitflags",
"d3d12",
@ -445,19 +451,20 @@ dependencies = [
[[package]]
name = "gfx-backend-empty"
version = "0.5.0"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67bd2d7bc022b257ddbdabc5fa3b10c29c292372c3409f2b6a6e3f4e11cdb85"
checksum = "2085227c12b78f6657a900c829f2d0deb46a9be3eaf86844fde263cdc218f77c"
dependencies = [
"gfx-hal",
"log",
"raw-window-handle",
]
[[package]]
name = "gfx-backend-metal"
version = "0.5.6"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92804d20b194de6c84cb4bec14ec6a6dcae9c51f0a9186817fb412a590131ae6"
checksum = "42518c5b571be5ba337a89cfba5abfaf2d90b83fc4db96357f64f2ea05f20f81"
dependencies = [
"arrayvec",
"bitflags",
@ -471,7 +478,7 @@ dependencies = [
"log",
"metal",
"objc",
"parking_lot",
"parking_lot 0.11.0",
"range-alloc",
"raw-window-handle",
"smallvec",
@ -481,15 +488,16 @@ dependencies = [
[[package]]
name = "gfx-backend-vulkan"
version = "0.5.11"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aec9c919cfc236d2c36aaa38609c1906a92f2df99a3c7f53022b01936f98275a"
checksum = "a84bda4200a82e1912d575801e2bb76ae19c6256359afbc0adfbbaec02fcadc6"
dependencies = [
"arrayvec",
"ash",
"byteorder",
"core-graphics-types",
"gfx-hal",
"inplace_it",
"lazy_static",
"log",
"objc",
@ -501,9 +509,11 @@ dependencies = [
[[package]]
name = "gfx-descriptor"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/gfx-extras?rev=473a4cdc63463e7986707507c4a7f6a3a767e329#473a4cdc63463e7986707507c4a7f6a3a767e329"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd8c7afcd000f279d541a490e27117e61037537279b9342279abf4938fe60c6b"
dependencies = [
"arrayvec",
"fxhash",
"gfx-hal",
"log",
@ -511,9 +521,9 @@ dependencies = [
[[package]]
name = "gfx-hal"
version = "0.5.3"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a18534b23d4c262916231511309bc1f307c74cda8dcb68b93a10ca213a22814b"
checksum = "18d0754f5b7a43915fd7466883b2d1bb0800d7cc4609178d0b27bf143b9e5123"
dependencies = [
"bitflags",
"raw-window-handle",
@ -521,8 +531,9 @@ dependencies = [
[[package]]
name = "gfx-memory"
version = "0.1.3"
source = "git+https://github.com/gfx-rs/gfx-extras?rev=473a4cdc63463e7986707507c4a7f6a3a767e329#473a4cdc63463e7986707507c4a7f6a3a767e329"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe8d8855df07f438eb8a765e90356d5b821d644ea3b59b870091450b89576a9f"
dependencies = [
"fxhash",
"gfx-hal",
@ -558,6 +569,12 @@ dependencies = [
"quick-error",
]
[[package]]
name = "inplace_it"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd01a2a73f2f399df96b22dc88ea687ef4d76226284e7531ae3c7ee1dc5cb534"
[[package]]
name = "instant"
version = "0.1.4"
@ -659,6 +676,15 @@ dependencies = [
"scopeguard",
]
[[package]]
name = "lock_api"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.8"
@ -778,8 +804,9 @@ dependencies = [
[[package]]
name = "naga"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/naga?rev=1eb637038dd15fc1dad770eca8e6943424dbc122#1eb637038dd15fc1dad770eca8e6943424dbc122"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0873deb76cf44b7454fba7b2ba6a89d3de70c08aceffd2c489379b3d9d08e661"
dependencies = [
"bitflags",
"fxhash",
@ -925,8 +952,19 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
dependencies = [
"lock_api",
"parking_lot_core",
"lock_api 0.3.4",
"parking_lot_core 0.7.2",
]
[[package]]
name = "parking_lot"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733"
dependencies = [
"instant",
"lock_api 0.4.1",
"parking_lot_core 0.8.0",
]
[[package]]
@ -936,7 +974,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
dependencies = [
"cfg-if",
"cloudabi",
"cloudabi 0.0.3",
"libc",
"redox_syscall",
"smallvec",
"winapi 0.3.8",
]
[[package]]
name = "parking_lot_core"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
dependencies = [
"cfg-if",
"cloudabi 0.1.0",
"instant",
"libc",
"redox_syscall",
"smallvec",
@ -1095,9 +1148,9 @@ checksum = "60d4a9058849c3e765fe2fa68b72c1416b1766f27eac3c52d7bac8712ea0d390"
[[package]]
name = "ron"
version = "0.5.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ece421e0c4129b90e4a35b6f625e472e96c552136f5093a2f4fa2bbb75a62d5"
checksum = "a91260f321dbf3b5a16ff91c451dc9eb644ce72775a6812f9c3dfffe63818f8f"
dependencies = [
"base64",
"bitflags",
@ -1223,9 +1276,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "1.4.0"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
[[package]]
name = "smithay-client-toolkit"
@ -1275,11 +1328,11 @@ dependencies = [
[[package]]
name = "storage-map"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd0a4829a5c591dc24a944a736d6b1e4053e51339a79fd5d4702c4c999a9c45e"
checksum = "418bb14643aa55a7841d5303f72cf512cfb323b8cc221d51580500a1ca75206c"
dependencies = [
"lock_api",
"lock_api 0.4.1",
]
[[package]]
@ -1582,7 +1635,7 @@ dependencies = [
"gfx-memory",
"loom",
"naga",
"parking_lot",
"parking_lot 0.11.0",
"raw-window-handle",
"ron",
"serde",
@ -1596,7 +1649,7 @@ dependencies = [
name = "wgpu-subscriber"
version = "0.1.0"
dependencies = [
"parking_lot",
"parking_lot 0.11.0",
"thread-id",
"tracing",
"tracing-log",
@ -1676,7 +1729,7 @@ dependencies = [
"ndk-glue",
"ndk-sys",
"objc",
"parking_lot",
"parking_lot 0.10.2",
"percent-encoding",
"raw-window-handle",
"smithay-client-toolkit",

View File

@ -19,7 +19,7 @@ env_logger = "0.7"
log = "0.4"
raw-window-handle = "0.3"
renderdoc = { version = "0.8", optional = true, default_features = false }
ron = "0.5"
ron = "0.6"
winit = { version = "0.22", optional = true }
[dependencies.wgt]
@ -39,7 +39,7 @@ path = "../wgpu-subscriber"
version = "0.1"
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { version = "0.5", features = ["x11"] }
gfx-backend-vulkan = { version = "0.6", features = ["x11"] }
[dev-dependencies]
serde = "1"

View File

@ -25,45 +25,40 @@ arrayvec = "0.5"
bitflags = "1.0"
copyless = "0.1"
fxhash = "0.2"
hal = { package = "gfx-hal", version = "0.5.3" }
gfx-backend-empty = "0.5"
parking_lot = "0.10"
hal = { package = "gfx-hal", version = "0.6" }
gfx-backend-empty = "0.6"
parking_lot = "0.11"
raw-window-handle = { version = "0.3", optional = true }
ron = { version = "0.5", optional = true }
ron = { version = "0.6", optional = true }
serde = { version = "1.0", features = ["serde_derive"], optional = true }
smallvec = "1"
tracing = { version = "0.1", default-features = false, features = ["std"] }
thiserror = "1"
gfx-descriptor = "0.2"
gfx-memory = "0.2"
[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "1eb637038dd15fc1dad770eca8e6943424dbc122"
version = "0.2"
#git = "https://github.com/gfx-rs/naga"
#rev = "1eb637038dd15fc1dad770eca8e6943424dbc122"
features = ["spirv"]
[dependencies.gfx-descriptor]
git = "https://github.com/gfx-rs/gfx-extras"
rev = "473a4cdc63463e7986707507c4a7f6a3a767e329"
[dependencies.gfx-memory]
git = "https://github.com/gfx-rs/gfx-extras"
rev = "473a4cdc63463e7986707507c4a7f6a3a767e329"
[dependencies.wgt]
path = "../wgpu-types"
package = "wgpu-types"
version = "0.5"
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
gfx-backend-metal = { version = "0.5.6" }
gfx-backend-vulkan = { version = "0.5.11", optional = true }
gfx-backend-metal = { version = "0.6" }
gfx-backend-vulkan = { version = "0.6", optional = true }
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { version = "0.5.11" }
gfx-backend-vulkan = { version = "0.6.1" }
[target.'cfg(windows)'.dependencies]
gfx-backend-dx12 = { version = "0.5.8" }
gfx-backend-dx11 = { version = "0.5" }
gfx-backend-vulkan = { version = "0.5.11" }
gfx-backend-dx12 = { version = "0.6" }
gfx-backend-dx11 = { version = "0.6" }
gfx-backend-vulkan = { version = "0.6" }
[dev-dependencies]
loom = "0.3"

View File

@ -14,8 +14,10 @@ use crate::{
resource::BufferUse,
span,
validation::{check_buffer_usage, MissingBufferUsageError},
MAX_BIND_GROUPS,
};
use arrayvec::ArrayVec;
use hal::command::CommandBuffer as _;
use thiserror::Error;
use wgt::{BufferAddress, BufferUsage, ShaderStage};
@ -212,6 +214,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pipeline: PipelineState::Required,
debug_scope_depth: 0,
};
let mut temp_offsets = Vec::new();
for command in base.commands {
match *command {
@ -228,7 +231,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
});
}
let offsets = &base.dynamic_offsets[..num_dynamic_offsets as usize];
temp_offsets.clear();
temp_offsets
.extend_from_slice(&base.dynamic_offsets[..num_dynamic_offsets as usize]);
base.dynamic_offsets = &base.dynamic_offsets[num_dynamic_offsets as usize..];
let bind_group = cmd_buf
@ -236,7 +241,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.bind_groups
.use_extend(&*bind_group_guard, bind_group_id, (), ())
.map_err(|_| ComputePassError::InvalidBindGroup(bind_group_id))?;
bind_group.validate_dynamic_bindings(offsets)?;
bind_group.validate_dynamic_bindings(&temp_offsets)?;
tracing::trace!(
"Encoding barriers on binding of {:?} to {:?}",
@ -255,22 +260,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
index as usize,
id::Valid(bind_group_id),
bind_group,
offsets,
&temp_offsets,
) {
let bind_groups = iter::once(bind_group.raw.raw()).chain(
let bind_groups = iter::once(bind_group.raw.raw())
.chain(
follow_ups
.clone()
.map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()),
);
)
.collect::<ArrayVec<[_; MAX_BIND_GROUPS]>>();
temp_offsets.extend(follow_ups.flat_map(|(_, offsets)| offsets));
unsafe {
raw.bind_compute_descriptor_sets(
&pipeline_layout_guard[pipeline_layout_id].raw,
index as usize,
bind_groups,
offsets
.iter()
.chain(follow_ups.flat_map(|(_, offsets)| offsets))
.cloned(),
&temp_offsets,
);
}
}

View File

@ -11,19 +11,19 @@ use crate::{
},
conv,
device::{
AttachmentData, FramebufferKey, RenderPassContext, RenderPassKey, MAX_COLOR_TARGETS,
MAX_VERTEX_BUFFERS,
AttachmentData, AttachmentDataVec, FramebufferKey, RenderPassContext, RenderPassKey,
MAX_COLOR_TARGETS, MAX_VERTEX_BUFFERS,
},
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
id,
pipeline::PipelineFlags,
resource::{BufferUse, TextureUse, TextureView, TextureViewInner},
span,
track::TrackerSet,
track::{TextureSelector, TrackerSet},
validation::{
check_buffer_usage, check_texture_usage, MissingBufferUsageError, MissingTextureUsageError,
},
Stored,
Stored, MAX_BIND_GROUPS,
};
use arrayvec::ArrayVec;
@ -460,12 +460,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
struct OutputAttachment<'a> {
texture_id: &'a Stored<id::TextureId>,
range: &'a hal::image::SubresourceRange,
selector: &'a TextureSelector,
previous_use: Option<TextureUse>,
new_use: TextureUse,
}
const MAX_TOTAL_ATTACHMENTS: usize = 2 * MAX_COLOR_TARGETS + 1;
let mut output_attachments = ArrayVec::<[OutputAttachment; MAX_TOTAL_ATTACHMENTS]>::new();
let mut output_attachments = AttachmentDataVec::<OutputAttachment>::new();
let context = {
use hal::device::Device as _;
@ -512,7 +511,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.use_extend(&*view_guard, at.attachment, (), ())
.map_err(|_| RenderPassError::InvalidAttachment(at.attachment))?;
add_view(view)?;
depth_stencil_aspects = view.range.aspects;
depth_stencil_aspects = view.aspects;
let source_id = match view.inner {
TextureViewInner::Native { ref source_id, .. } => source_id,
@ -524,8 +523,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
// Using render pass for transition.
let previous_use = base_trackers
.textures
.query(source_id.value, view.range.clone());
let new_use = if at.is_read_only(view.range.aspects)? {
.query(source_id.value, view.selector.clone());
let new_use = if at.is_read_only(view.aspects)? {
is_ds_read_only = true;
TextureUse::ATTACHMENT_READ
} else {
@ -533,14 +532,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
output_attachments.push(OutputAttachment {
texture_id: source_id,
range: &view.range,
selector: &view.selector,
previous_use,
new_use,
});
let new_layout = conv::map_texture_state(new_use, view.range.aspects).1;
let new_layout = conv::map_texture_state(new_use, view.aspects).1;
let old_layout = match previous_use {
Some(usage) => conv::map_texture_state(usage, view.range.aspects).1,
Some(usage) => conv::map_texture_state(usage, view.aspects).1,
None => new_layout,
};
@ -573,11 +572,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
TextureViewInner::Native { ref source_id, .. } => {
let previous_use = base_trackers
.textures
.query(source_id.value, view.range.clone());
.query(source_id.value, view.selector.clone());
let new_use = TextureUse::ATTACHMENT_WRITE;
output_attachments.push(OutputAttachment {
texture_id: source_id,
range: &view.range,
selector: &view.selector,
previous_use,
new_use,
});
@ -646,11 +645,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
TextureViewInner::Native { ref source_id, .. } => {
let previous_use = base_trackers
.textures
.query(source_id.value, view.range.clone());
.query(source_id.value, view.selector.clone());
let new_use = TextureUse::ATTACHMENT_WRITE;
output_attachments.push(OutputAttachment {
texture_id: source_id,
range: &view.range,
selector: &view.selector,
previous_use,
new_use,
});
@ -755,7 +754,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
inputs: &[],
preserves: &[],
};
let all = entry.key().all().map(|(at, _)| at);
let all = entry
.key()
.all()
.map(|(at, _)| at)
.collect::<AttachmentDataVec<_>>();
let pass =
unsafe { device.raw.create_render_pass(all, iter::once(subpass), &[]) }
@ -798,10 +801,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Some(sc_id) => {
assert!(cmd_buf.used_swap_chain.is_none());
// Always create a new framebuffer and delete it after presentation.
let attachments = fb_key.all().map(|&id| match view_guard[id].inner {
let attachments = fb_key
.all()
.map(|&id| match view_guard[id].inner {
TextureViewInner::Native { ref raw, .. } => raw,
TextureViewInner::SwapChain { ref image, .. } => Borrow::borrow(image),
});
})
.collect::<AttachmentDataVec<_>>();
let framebuffer = unsafe {
device
.raw
@ -818,13 +824,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Entry::Occupied(e) => e.into_mut(),
Entry::Vacant(e) => {
let fb = {
let attachments =
e.key().all().map(|&id| match view_guard[id].inner {
let attachments = e
.key()
.all()
.map(|&id| match view_guard[id].inner {
TextureViewInner::Native { ref raw, .. } => raw,
TextureViewInner::SwapChain { ref image, .. } => {
Borrow::borrow(image)
}
});
})
.collect::<AttachmentDataVec<_>>();
unsafe {
device
.raw
@ -895,7 +904,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
})
}
}
}));
}))
.collect::<ArrayVec<[_; MAX_COLOR_TARGETS + 1]>>();
unsafe {
raw.begin_render_pass(
@ -927,6 +937,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
vertex: VertexState::default(),
debug_scope_depth: 0,
};
let mut temp_offsets = Vec::new();
for command in base.commands {
match *command {
@ -944,7 +955,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.into());
}
let offsets = &base.dynamic_offsets[..num_dynamic_offsets as usize];
temp_offsets.clear();
temp_offsets
.extend_from_slice(&base.dynamic_offsets[..num_dynamic_offsets as usize]);
base.dynamic_offsets = &base.dynamic_offsets[num_dynamic_offsets as usize..];
let bind_group = trackers
@ -952,7 +965,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.use_extend(&*bind_group_guard, bind_group_id, (), ())
.unwrap();
bind_group
.validate_dynamic_bindings(offsets)
.validate_dynamic_bindings(&temp_offsets)
.map_err(RenderPassError::from)?;
trackers.merge_extend(&bind_group.used);
@ -961,22 +974,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
index as usize,
id::Valid(bind_group_id),
bind_group,
offsets,
&temp_offsets,
) {
let bind_groups = iter::once(bind_group.raw.raw()).chain(
let bind_groups = iter::once(bind_group.raw.raw())
.chain(
follow_ups
.clone()
.map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()),
);
)
.collect::<ArrayVec<[_; MAX_BIND_GROUPS]>>();
temp_offsets.extend(follow_ups.flat_map(|(_, offsets)| offsets));
unsafe {
raw.bind_graphics_descriptor_sets(
&pipeline_layout_guard[pipeline_layout_id].raw,
index as usize,
bind_groups,
offsets
.iter()
.chain(follow_ups.flat_map(|(_, offsets)| offsets))
.cloned(),
&temp_offsets,
);
}
};
@ -1503,7 +1516,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.change_extend(
ot.texture_id.value,
&ot.texture_id.ref_count,
ot.range.clone(),
ot.selector.clone(),
ot.new_use,
)
.unwrap();
@ -1517,7 +1530,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.prepend(
ot.texture_id.value,
&ot.texture_id.ref_count,
ot.range.clone(),
ot.selector.clone(),
usage,
)
.unwrap();

View File

@ -12,6 +12,7 @@ use crate::{
id::{BufferId, CommandEncoderId, TextureId},
resource::{BufferUse, Texture, TextureUse},
span,
track::TextureSelector,
};
use hal::command::CommandBuffer as _;
@ -82,7 +83,7 @@ pub(crate) fn texture_copy_view_to_hal<B: hal::Backend>(
) -> Result<
(
hal::image::SubresourceLayers,
hal::image::SubresourceRange,
TextureSelector,
hal::image::Offset,
),
TransferError,
@ -90,7 +91,7 @@ pub(crate) fn texture_copy_view_to_hal<B: hal::Backend>(
let texture = texture_guard
.get(view.texture)
.map_err(|_| TransferError::InvalidTexture(view.texture))?;
let aspects = texture.full_range.aspects;
let level = view.mip_level as hal::image::Level;
let (layer, layer_count, z) = match texture.dimension {
wgt::TextureDimension::D1 | wgt::TextureDimension::D2 => (
@ -102,16 +103,15 @@ pub(crate) fn texture_copy_view_to_hal<B: hal::Backend>(
};
// TODO: Can't satisfy clippy here unless we modify
// `hal::image::SubresourceRange` in gfx to use `std::ops::RangeBounds`.
// `TextureSelector` to use `std::ops::RangeBounds`.
#[allow(clippy::range_plus_one)]
Ok((
hal::image::SubresourceLayers {
aspects,
level: view.mip_level as hal::image::Level,
aspects: texture.aspects,
level,
layers: layer..layer + layer_count,
},
hal::image::SubresourceRange {
aspects,
TextureSelector {
levels: level..level + 1,
layers: layer..layer + layer_count,
},
@ -349,7 +349,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let cmd_buf = CommandBuffer::get_encoder(&mut *cmd_buf_guard, command_encoder_id)?;
let (buffer_guard, mut token) = hub.buffers.read(&mut token);
let (texture_guard, _) = hub.textures.read(&mut token);
let (dst_layers, dst_range, dst_offset) =
let (dst_layers, dst_selector, dst_offset) =
texture_copy_view_to_hal(destination, copy_size, &*texture_guard)?;
#[cfg(feature = "trace")]
@ -383,7 +383,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.use_replace(
&*texture_guard,
destination.texture,
dst_range,
dst_selector,
TextureUse::COPY_DST,
)
.unwrap();
@ -456,7 +456,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let cmd_buf = CommandBuffer::get_encoder(&mut *cmd_buf_guard, command_encoder_id)?;
let (buffer_guard, mut token) = hub.buffers.read(&mut token);
let (texture_guard, _) = hub.textures.read(&mut token);
let (src_layers, src_range, src_offset) =
let (src_layers, src_selector, src_offset) =
texture_copy_view_to_hal(source, copy_size, &*texture_guard)?;
#[cfg(feature = "trace")]
@ -480,7 +480,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.use_replace(
&*texture_guard,
source.texture,
src_range,
src_selector,
TextureUse::COPY_SRC,
)
.unwrap();
@ -567,9 +567,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
// we can't hold both src_pending and dst_pending in scope because they
// borrow the buffer tracker mutably...
let mut barriers = Vec::new();
let (src_layers, src_range, src_offset) =
let (src_layers, src_selector, src_offset) =
texture_copy_view_to_hal(source, copy_size, &*texture_guard)?;
let (dst_layers, dst_range, dst_offset) =
let (dst_layers, dst_selector, dst_offset) =
texture_copy_view_to_hal(destination, copy_size, &*texture_guard)?;
if src_layers.aspects != dst_layers.aspects {
Err(TransferError::MismatchedAspects)?
@ -596,7 +596,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.use_replace(
&*texture_guard,
source.texture,
src_range,
src_selector,
TextureUse::COPY_SRC,
)
.unwrap();
@ -611,7 +611,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.use_replace(
&*texture_guard,
destination.texture,
dst_range,
dst_selector,
TextureUse::COPY_DST,
)
.unwrap();

View File

@ -10,7 +10,7 @@ use crate::{
GfxBackend, Global, GlobalIdentityHandlerFactory, Hub, Input, InvalidId, Storage, Token,
},
id, pipeline, resource, span, swap_chain,
track::{BufferState, TextureState, TrackerSet},
track::{BufferState, TextureSelector, TextureState, TrackerSet},
validation::{self, check_buffer_usage, check_texture_usage},
FastHashMap, Label, LifeGuard, MultiRefCount, PrivateFeatures, Stored, SubmissionIndex,
MAX_BIND_GROUPS,
@ -95,6 +95,8 @@ impl<T> AttachmentData<T> {
}
}
pub(crate) type AttachmentDataVec<T> = ArrayVec<[T; MAX_COLOR_TARGETS + MAX_COLOR_TARGETS + 1]>;
pub(crate) type RenderPassKey = AttachmentData<(hal::pass::Attachment, hal::image::Layout)>;
pub(crate) type FramebufferKey = AttachmentData<id::Valid<id::TextureViewId>>;
@ -540,11 +542,11 @@ impl<B: GfxBackend> Device<B> {
ref_count: self.life_guard.add_ref(),
},
usage: desc.usage,
aspects,
dimension: desc.dimension,
kind,
format: desc.format,
full_range: hal::image::SubresourceRange {
aspects,
full_range: TextureSelector {
levels: 0..desc.mip_level_count as hal::image::Level,
layers: 0..kind.num_layers(),
},
@ -580,7 +582,10 @@ impl<B: GfxBackend> Device<B> {
resolves: &[],
preserves: &[],
};
let all = key.all().map(|(at, _)| at);
let all = key
.all()
.map(|(at, _)| at)
.collect::<AttachmentDataVec<_>>();
unsafe { self.raw.create_render_pass(all, iter::once(subpass), &[]) }
}
@ -1222,7 +1227,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.get(device_id)
.map_err(|_| DeviceError::Invalid)?;
let texture = device.create_texture(device_id, desc)?;
let range = texture.full_range.clone();
let num_levels = texture.full_range.levels.end;
let num_layers = texture.full_range.layers.end;
let ref_count = texture.life_guard.add_ref();
let id = hub.textures.register_identity(id_in, texture, &mut token);
@ -1247,7 +1253,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.trackers
.lock()
.textures
.init(id, ref_count, TextureState::with_range(&range))
.init(id, ref_count, TextureState::new(num_levels, num_layers))
.unwrap();
Ok(id.0)
}
@ -1335,29 +1341,26 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
total: layer_end,
});
};
let end_level = desc
.level_count
.map_or(level_end, |_| required_level_count as u8);
let end_layer = desc
.array_layer_count
.map_or(layer_end, |_| required_layer_count as u16);
let aspects = match desc.aspect {
wgt::TextureAspect::All => texture.full_range.aspects,
wgt::TextureAspect::All => texture.aspects,
wgt::TextureAspect::DepthOnly => hal::format::Aspects::DEPTH,
wgt::TextureAspect::StencilOnly => hal::format::Aspects::STENCIL,
};
if !texture.full_range.aspects.contains(aspects) {
if !texture.aspects.contains(aspects) {
return Err(resource::CreateTextureViewError::InvalidAspect {
requested: aspects,
total: texture.full_range.aspects,
total: texture.aspects,
});
}
let format = desc.format.unwrap_or(texture.format);
let range = hal::image::SubresourceRange {
aspects,
levels: desc.base_mip_level as u8..end_level,
layers: desc.base_array_layer as u16..end_layer,
level_start: desc.base_mip_level as _,
level_count: desc.level_count.map(|v| v.get() as _),
layer_start: desc.base_array_layer as _,
layer_count: desc.array_layer_count.map(|v| v.get() as _),
};
let raw = unsafe {
@ -1373,6 +1376,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.or(Err(resource::CreateTextureViewError::OutOfMemory))?
};
let end_level = desc
.level_count
.map_or(level_end, |_| required_level_count as u8);
let end_layer = desc
.array_layer_count
.map_or(layer_end, |_| required_layer_count as u16);
let selector = TextureSelector {
levels: desc.base_mip_level as u8..end_level,
layers: desc.base_array_layer as u16..end_layer,
};
let view = resource::TextureView {
inner: resource::TextureViewInner::Native {
raw,
@ -1381,10 +1395,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
ref_count: texture.life_guard.add_ref(),
},
},
aspects,
format: texture.format,
extent: texture.kind.extent().at_level(range.levels.start),
extent: texture.kind.extent().at_level(desc.base_mip_level as _),
samples: texture.kind.num_samples(),
range,
selector,
life_guard: LifeGuard::new(),
};
let ref_count = view.life_guard.add_ref();
@ -2056,7 +2071,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
})
};
if view
.range
.aspects
.contains(hal::format::Aspects::DEPTH | hal::format::Aspects::STENCIL)
{
@ -2074,13 +2088,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.change_extend(
source_id.value,
&source_id.ref_count,
view.range.clone(),
view.selector.clone(),
internal_use,
)
.unwrap();
check_texture_usage(texture.usage, pub_usage)?;
let image_layout =
conv::map_texture_state(internal_use, view.range.aspects).1;
conv::map_texture_state(internal_use, view.aspects).1;
SmallVec::from([hal::pso::Descriptor::Image(raw, image_layout)])
}
resource::TextureViewInner::SwapChain { .. } => {
@ -2138,16 +2152,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.change_extend(
source_id.value,
&source_id.ref_count,
view.range.clone(),
view.selector.clone(),
internal_use,
)
.unwrap();
check_texture_usage(texture.usage, pub_usage)?;
let image_layout = conv::map_texture_state(
internal_use,
view.range.aspects,
)
.1;
let image_layout =
conv::map_texture_state(internal_use, view.aspects).1;
Ok(hal::pso::Descriptor::Image(raw, image_layout))
}
resource::TextureViewInner::SwapChain { .. } => {
@ -2822,12 +2833,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(pipeline::ImplicitLayoutError::ReflectionError(last_stage))?
}
let shaders = hal::pso::GraphicsShaderSet {
let primitive_assembler = hal::pso::PrimitiveAssemblerDesc::Vertex {
buffers: &vertex_buffers,
attributes: &attributes,
input_assembler,
vertex,
hull: None,
domain: None,
tessellation: None,
geometry: None,
fragment,
};
// TODO
@ -2852,11 +2864,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut render_pass_cache = device.render_passes.lock();
let pipeline_desc = hal::pso::GraphicsPipelineDesc {
shaders,
primitive_assembler,
rasterizer,
vertex_buffers,
attributes,
input_assembler,
fragment,
blender,
depth_stencil,
multisampling,

View File

@ -5,7 +5,7 @@
use crate::{
device::DeviceError,
id::{DeviceId, SwapChainId, TextureId},
track::DUMMY_SELECTOR,
track::{TextureSelector, DUMMY_SELECTOR},
validation::MissingBufferUsageError,
Label, LifeGuard, RefCount, Stored,
};
@ -204,10 +204,11 @@ pub struct Texture<B: hal::Backend> {
pub(crate) raw: B::Image,
pub(crate) device_id: Stored<DeviceId>,
pub(crate) usage: wgt::TextureUsage,
pub(crate) aspects: hal::format::Aspects,
pub(crate) dimension: wgt::TextureDimension,
pub(crate) kind: hal::image::Kind,
pub(crate) format: wgt::TextureFormat,
pub(crate) full_range: hal::image::SubresourceRange,
pub(crate) full_range: TextureSelector,
pub(crate) memory: MemoryBlock<B>,
pub(crate) life_guard: LifeGuard,
}
@ -242,8 +243,8 @@ impl<B: hal::Backend> Borrow<RefCount> for Texture<B> {
}
}
impl<B: hal::Backend> Borrow<hal::image::SubresourceRange> for Texture<B> {
fn borrow(&self) -> &hal::image::SubresourceRange {
impl<B: hal::Backend> Borrow<TextureSelector> for Texture<B> {
fn borrow(&self) -> &TextureSelector {
&self.full_range
}
}
@ -293,10 +294,11 @@ pub(crate) enum TextureViewInner<B: hal::Backend> {
pub struct TextureView<B: hal::Backend> {
pub(crate) inner: TextureViewInner<B>,
//TODO: store device_id for quick access?
pub(crate) aspects: hal::format::Aspects,
pub(crate) format: wgt::TextureFormat,
pub(crate) extent: hal::image::Extent,
pub(crate) samples: hal::image::NumSamples,
pub(crate) range: hal::image::SubresourceRange,
pub(crate) selector: TextureSelector,
pub(crate) life_guard: LifeGuard,
}

View File

@ -39,7 +39,9 @@ use crate::{
device::DeviceError,
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
id::{DeviceId, SwapChainId, TextureViewId, Valid},
resource, span, LifeGuard, PrivateFeatures, Stored, SubmissionIndex,
resource, span,
track::TextureSelector,
LifeGuard, PrivateFeatures, Stored, SubmissionIndex,
};
use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _};
@ -184,6 +186,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
ref_count: sc.life_guard.add_ref(),
},
},
aspects: hal::format::Aspects::COLOR,
format: sc.desc.format,
extent: hal::image::Extent {
width: sc.desc.width,
@ -191,8 +194,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
depth: 1,
},
samples: 1,
range: hal::image::SubresourceRange {
aspects: hal::format::Aspects::COLOR,
selector: TextureSelector {
layers: 0..1,
levels: 0..1,
},
@ -272,7 +274,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
None
};
let queue = &mut device.queue_group.queues[0];
let result = unsafe { queue.present_surface(B::get_surface_mut(surface), image, sem) };
let result = unsafe { queue.present(B::get_surface_mut(surface), image, sem) };
tracing::debug!(trace = true, "Presented. End of Frame");

View File

@ -19,7 +19,7 @@ use std::{
use thiserror::Error;
pub(crate) use buffer::BufferState;
pub(crate) use texture::TextureState;
pub(crate) use texture::{TextureSelector, TextureState};
/// A single unit of state tracking. It keeps an initial
/// usage as well as the last/current one, similar to `Range`.
@ -151,14 +151,17 @@ impl PendingTransition<TextureState> {
tex: &'a resource::Texture<B>,
) -> hal::memory::Barrier<'a, B> {
tracing::trace!("\ttexture -> {:?}", self);
let aspects = tex.full_range.aspects;
let aspects = tex.aspects;
hal::memory::Barrier::Image {
states: conv::map_texture_state(self.usage.start, aspects)
..conv::map_texture_state(self.usage.end, aspects),
target: &tex.raw,
range: hal::image::SubresourceRange {
aspects,
..self.selector
level_start: self.selector.levels.start,
level_count: Some(self.selector.levels.end - self.selector.levels.start),
layer_start: self.selector.layers.start,
layer_count: Some(self.selector.layers.end - self.selector.layers.start),
},
families: None,
}

View File

@ -16,6 +16,13 @@ use std::{iter, ops::Range};
//TODO: store `hal::image::State` here to avoid extra conversions
type PlaneStates = RangedStates<hal::image::Layer, Unit<TextureUse>>;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TextureSelector {
//pub aspects: hal::format::Aspects,
pub levels: Range<hal::image::Level>,
pub layers: Range<hal::image::Layer>,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub(crate) struct TextureState {
mips: ArrayVec<[PlaneStates; MAX_MIP_LEVELS as usize]>,
@ -37,14 +44,12 @@ impl PendingTransition<TextureState> {
}
impl TextureState {
pub fn with_range(range: &hal::image::SubresourceRange) -> Self {
debug_assert_eq!(range.layers.start, 0);
debug_assert_eq!(range.levels.start, 0);
pub fn new(mip_level_count: hal::image::Level, array_layer_count: hal::image::Layer) -> Self {
TextureState {
mips: iter::repeat_with(|| {
PlaneStates::from_range(0..range.layers.end, Unit::new(TextureUse::UNINITIALIZED))
PlaneStates::from_range(0..array_layer_count, Unit::new(TextureUse::UNINITIALIZED))
})
.take(range.levels.end as usize)
.take(mip_level_count as usize)
.collect(),
full: true,
}
@ -53,7 +58,7 @@ impl TextureState {
impl ResourceState for TextureState {
type Id = TextureId;
type Selector = hal::image::SubresourceRange;
type Selector = TextureSelector;
type Usage = TextureUse;
fn query(&self, selector: Self::Selector) -> Option<Self::Usage> {
@ -106,13 +111,11 @@ impl ResourceState for TextureState {
continue;
}
// TODO: Can't satisfy clippy here unless we modify
// `hal::image::SubresourceRange` in gfx to use
// `std::ops::RangeBounds`.
// `TextureSelector` to use `std::ops::RangeBounds`.
#[allow(clippy::range_plus_one)]
let pending = PendingTransition {
id,
selector: hal::image::SubresourceRange {
aspects: hal::format::Aspects::empty(),
selector: TextureSelector {
levels: level..level + 1,
layers: range.clone(),
},
@ -158,8 +161,7 @@ impl ResourceState for TextureState {
Some(old) if old != usage => {
return Err(PendingTransition {
id,
selector: hal::image::SubresourceRange {
aspects: hal::format::Aspects::empty(),
selector: TextureSelector {
levels: level..level + 1,
layers: range.clone(),
},
@ -224,13 +226,11 @@ impl ResourceState for TextureState {
}
} else {
// TODO: Can't satisfy clippy here unless we modify
// `hal::image::SubresourceRange` in gfx to use
// `std::ops::RangeBounds`.
// `TextureSelector` to use `std::ops::RangeBounds`.
#[allow(clippy::range_plus_one)]
let pending = PendingTransition {
id,
selector: hal::image::SubresourceRange {
aspects: hal::format::Aspects::empty(),
selector: TextureSelector {
levels: level..level + 1,
layers: layers.clone(),
},
@ -276,7 +276,6 @@ mod test {
//TODO: change() tests
use super::*;
use crate::id::Id;
use hal::{format::Aspects, image::SubresourceRange};
#[test]
fn query() {
@ -289,8 +288,7 @@ mod test {
]));
assert_eq!(
ts.query(SubresourceRange {
aspects: Aspects::COLOR,
ts.query(TextureSelector {
levels: 1..2,
layers: 2..5,
}),
@ -298,8 +296,7 @@ mod test {
Some(TextureUse::SAMPLED),
);
assert_eq!(
ts.query(SubresourceRange {
aspects: Aspects::COLOR,
ts.query(TextureSelector {
levels: 0..2,
layers: 2..5,
}),
@ -307,8 +304,7 @@ mod test {
Some(TextureUse::SAMPLED),
);
assert_eq!(
ts.query(SubresourceRange {
aspects: Aspects::COLOR,
ts.query(TextureSelector {
levels: 1..2,
layers: 1..5,
}),
@ -316,8 +312,7 @@ mod test {
Some(TextureUse::SAMPLED),
);
assert_eq!(
ts.query(SubresourceRange {
aspects: Aspects::COLOR,
ts.query(TextureSelector {
levels: 1..2,
layers: 4..6,
}),
@ -364,8 +359,7 @@ mod test {
ts1.clone().merge(Id::dummy(), &ts2, None),
Err(PendingTransition {
id,
selector: SubresourceRange {
aspects: Aspects::empty(),
selector: TextureSelector {
levels: 0..1,
layers: 1..2,
},
@ -391,8 +385,7 @@ mod test {
&[
PendingTransition {
id,
selector: SubresourceRange {
aspects: Aspects::empty(),
selector: TextureSelector {
levels: 0..1,
layers: 1..2,
},
@ -400,8 +393,7 @@ mod test {
},
PendingTransition {
id,
selector: SubresourceRange {
aspects: Aspects::empty(),
selector: TextureSelector {
levels: 0..1,
layers: 2..3,
},
@ -453,8 +445,7 @@ mod test {
&list,
&[PendingTransition {
id,
selector: SubresourceRange {
aspects: Aspects::empty(),
selector: TextureSelector {
levels: 0..1,
layers: 2..3,
},

View File

@ -14,7 +14,7 @@ license = "MPL-2.0"
[features]
[dependencies]
parking_lot = "0.10"
parking_lot = "0.11"
thread-id = "3"
tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing-log = "0.1"