Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for raw vulkan types #1415

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,26 @@ thiserror = "1"
gpu-alloc = "0.4"
gpu-descriptor = "0.1"

hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085" }
gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085" }

[target.'cfg(all(not(target_arch = "wasm32"), all(unix, not(target_os = "ios"), not(target_os = "macos"))))'.dependencies]
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521", features = ["naga"] }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085", features = ["naga"] }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085" }
ash = "0.32"

[target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies]
gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085" }
#TODO: could also depend on gfx-backend-vulkan for Vulkan Portability

[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521", features = ["naga"] }
gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085" }
gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085", features = ["naga"] }
ash = "0.32"

[target.'cfg(target_arch = "wasm32")'.dependencies]
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "7a60e1c13abef5973c22f2194c539403871f1085" }

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
Expand Down
53 changes: 44 additions & 9 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ fn check_device_features(
}

struct RenderAttachment<'a> {
texture_id: &'a Stored<id::TextureId>,
texture_id: Option<&'a Stored<id::TextureId>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it optional now?

selector: &'a TextureSelector,
previous_use: Option<TextureUse>,
new_use: TextureUse,
Expand Down Expand Up @@ -582,6 +582,9 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
TextureViewInner::SwapChain { .. } => {
return Err(RenderPassErrorInner::SwapChainImageAsDepthStencil);
}
TextureViewInner::Raw { .. } => {
return Err(RenderPassErrorInner::SwapChainImageAsDepthStencil);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong error

}
};

// Using render pass for transition.
Expand All @@ -596,7 +599,7 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
TextureUse::ATTACHMENT_WRITE
};
render_attachments.push(RenderAttachment {
texture_id: source_id,
texture_id: Some(source_id),
selector: &view.selector,
previous_use,
new_use,
Expand Down Expand Up @@ -647,7 +650,7 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
.query(source_id.value, view.selector.clone());
let new_use = TextureUse::ATTACHMENT_WRITE;
render_attachments.push(RenderAttachment {
texture_id: source_id,
texture_id: Some(source_id),
selector: &view.selector,
previous_use,
new_use,
Expand All @@ -674,6 +677,31 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
};
start..end
}
TextureViewInner::Raw { .. } => {
/* TODO:
let previous_use = cmd_buf
.trackers
.textures
.query(source_id.value, view.selector.clone());*/
let previous_use = None;
let new_use = TextureUse::ATTACHMENT_WRITE;
render_attachments.push(RenderAttachment {
texture_id: None,
selector: &view.selector,
previous_use,
new_use,
});

let new_layout =
conv::map_texture_state(new_use, hal::format::Aspects::COLOR).1;
let old_layout = match previous_use {
Some(usage) => {
conv::map_texture_state(usage, hal::format::Aspects::COLOR).1
}
None => new_layout,
};
old_layout..new_layout
}
};

let color_at = hal::pass::Attachment {
Expand Down Expand Up @@ -715,7 +743,7 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
.query(source_id.value, view.selector.clone());
let new_use = TextureUse::ATTACHMENT_WRITE;
render_attachments.push(RenderAttachment {
texture_id: source_id,
texture_id: Some(source_id),
selector: &view.selector,
previous_use,
new_use,
Expand All @@ -736,6 +764,10 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
used_swap_chain = Some(source_id.clone());
hal::image::Layout::Undefined..hal::image::Layout::Present
}
TextureViewInner::Raw { .. } => {
// TODO: This is only valid for OpenXR
hal::image::Layout::ColorAttachmentOptimal..hal::image::Layout::ColorAttachmentOptimal
}
};

let resolve_at = hal::pass::Attachment {
Expand Down Expand Up @@ -880,6 +912,7 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
let raw_views = view_data.map(|view| match view.inner {
TextureViewInner::Native { ref raw, .. } => raw,
TextureViewInner::SwapChain { ref image, .. } => Borrow::borrow(image),
TextureViewInner::Raw { ref raw } => raw,
});

//Note: the order of iteration has to match `AttachmentData::all()`
Expand Down Expand Up @@ -977,15 +1010,17 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
profiling::scope!("finish", "RenderPassInfo");

for ra in self.render_attachments {
let texture = &texture_guard[ra.texture_id.value];
let texture_id = if let Some(id) = ra.texture_id { id } else { continue };

let texture = &texture_guard[texture_id.value];
check_texture_usage(texture.usage, TextureUsage::RENDER_ATTACHMENT)?;

// the tracker set of the pass is always in "extend" mode
self.trackers
.textures
.change_extend(
ra.texture_id.value,
&ra.texture_id.ref_count,
texture_id.value,
&texture_id.ref_count,
ra.selector.clone(),
ra.new_use,
)
Expand All @@ -998,8 +1033,8 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
self.trackers
.textures
.prepend(
ra.texture_id.value,
&ra.texture_id.ref_count,
texture_id.value,
&texture_id.ref_count,
ra.selector.clone(),
usage,
)
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/device/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ impl<B: GfxBackend> LifetimeTracker<B> {
raw
}
resource::TextureViewInner::SwapChain { .. } => unreachable!(),
resource::TextureViewInner::Raw { .. } => unreachable!(),
};

let submit_index = res.life_guard.submission_index.load(Ordering::Acquire);
Expand Down
Loading