Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3a2bbfd
hal/dx12: adapter initialization
kvark Jul 5, 2021
eb565a5
hal/dx12: move device and encoder into modules
kvark Jul 5, 2021
0942fb1
hal/dx12: swap chain configuration
kvark Jul 5, 2021
971aee0
hal/dx12: buffer creation, device idling
kvark Jul 5, 2021
c01f6a5
hal/dx12: enable the backend in wgpu-core
kvark Jul 5, 2021
23615aa
hal/dx12: texture and view creation
kvark Jul 6, 2021
925ece8
hal/dx12: creation of RTV/DSV/UAV
kvark Jul 6, 2021
c751943
Filter texture usages on view creation
kvark Jul 6, 2021
8556894
hal/dx12: fences
kvark Jul 7, 2021
04ca321
hal/dx12: intercept debug output
kvark Jul 7, 2021
904621e
hal/dx12: sampler and query set creation
kvark Jul 7, 2021
e128021
hal/dx12: pipeline layout
kvark Jul 7, 2021
43a39a2
hal/dx12: command pooling
kvark Jul 7, 2021
4f6812f
hal/dx12: resource barriers
kvark Jul 7, 2021
f79c378
hal/dx12: buffer-buffer and texture-texture copies
kvark Jul 8, 2021
35ee657
hal: make copy to work on one array layer at a time
kvark Jul 8, 2021
2c76b0e
hal/dx12: clippy fixes, buffer-texture copies
kvark Jul 8, 2021
9069c23
hal/dx12: implement fill_buffer with zero
kvark Jul 8, 2021
b818157
hal/dx12: draws and dispatches
kvark Jul 9, 2021
27b8085
hal/dx12: queries
kvark Jul 9, 2021
1f91c5f
hal/dx12: debug markers
kvark Jul 9, 2021
81f31f5
hal: change blend color argument
kvark Jul 9, 2021
12bc3eb
hal/dx12: set render targets
kvark Jul 9, 2021
00859b9
Stop using render pass boundary usages for resource transitions
kvark Jul 9, 2021
ba1bff5
hal/dx12: attachment clears and resolvess
kvark Jul 9, 2021
c043276
hal/dx12: use range-alloc for descriptor heaps
kvark Jul 9, 2021
7d29a3b
hal/dx12: binding resources and index/vertex buffers
kvark Jul 10, 2021
040a602
hal/dx12: bind group creation
kvark Jul 11, 2021
0a609e7
hal/dx12: compute pipelines, update naga
kvark Jul 12, 2021
8163dc7
hal/dx12: pipeline creation
kvark Jul 13, 2021
450e5dc
hal/dx12: queue operations
kvark Jul 13, 2021
7fb0315
hal/dx12: build fixes for the new arrayvec
kvark Jul 13, 2021
0df804e
hal/dx12: bunch of validation fixes
kvark Jul 13, 2021
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
22 changes: 21 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you are looking for the native implementation or bindings to the API in other
API | Windows 7/10 | Linux & Android | macOS & iOS |
----- | ------------------ | ------------------ | ------------------ |
DX11 | :construction: | | |
DX12 | :construction: | | |
DX12 | :ok: | | |
Vulkan | :white_check_mark: | :white_check_mark: | |
Metal | | | :white_check_mark: |
GLes3 | | :ok: | |
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ thiserror = "1"

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "0b9af95793e319817e74a30601cbcd4bad9bb3e6"
rev = "458db0b"
features = ["wgsl-in"]

[dependencies.wgt]
Expand All @@ -57,7 +57,7 @@ hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["metal"] }
hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["vulkan", "gles"] }

[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["vulkan"] }
hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["vulkan", "dx12"] }

[build-dependencies]
cfg_aliases = "0.1"
2 changes: 1 addition & 1 deletion wgpu-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
// Backends
vulkan: { all(not(wasm), any(windows, unix_wo_apple)) },
metal: { all(not(wasm), apple) },
dx12: { all(false, not(wasm), windows) },
dx12: { all(not(wasm), windows) },
dx11: { all(false, not(wasm), windows) },
gl: { all(not(wasm), unix_wo_apple) },
}
Expand Down
142 changes: 70 additions & 72 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
pipeline::PipelineFlags,
resource::{Texture, TextureView, TextureViewSource},
swap_chain::SwapChain,
track::{StatefulTrackerSubset, TextureSelector, UsageConflict},
validation::{
check_buffer_usage, check_texture_usage, MissingBufferUsageError, MissingTextureUsageError,
Expand Down Expand Up @@ -491,11 +492,11 @@ where
struct RenderAttachment<'a> {
texture_id: &'a Stored<id::TextureId>,
selector: &'a TextureSelector,
previous_use: Option<hal::TextureUses>,
new_use: hal::TextureUses,
usage: hal::TextureUses,
}

type AttachmentDataVec<T> = ArrayVec<T, { hal::MAX_COLOR_TARGETS + hal::MAX_COLOR_TARGETS + 1 }>;
const MAX_TOTAL_ATTACHMENTS: usize = hal::MAX_COLOR_TARGETS + hal::MAX_COLOR_TARGETS + 1;
type AttachmentDataVec<T> = ArrayVec<T, MAX_TOTAL_ATTACHMENTS>;

struct RenderPassInfo<'a, A: hal::Api> {
context: RenderPassContext,
Expand All @@ -514,6 +515,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
depth_stencil_attachment: Option<&RenderPassDepthStencilAttachment>,
cmd_buf: &mut CommandBuffer<A>,
view_guard: &'a Storage<TextureView<A>, id::TextureViewId>,
swap_chain_guard: &'a Storage<SwapChain<A>, id::SwapChainId>,
) -> Result<Self, RenderPassErrorInner> {
profiling::scope!("start", "RenderPassInfo");

Expand All @@ -527,7 +529,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
let mut attachment_type_name = "";
let mut extent = None;
let mut sample_count = 0;
let mut used_swap_chain = None::<Stored<id::SwapChainId>>;
let mut used_swap_chain = None::<(Stored<id::SwapChainId>, hal::TextureUses)>;

let mut add_view = |view: &TextureView<A>, type_name| {
if let Some(ex) = extent {
Expand Down Expand Up @@ -577,12 +579,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
}
};

// Using render pass for transition.
let previous_use = cmd_buf
.trackers
.textures
.query(source_id.value, view.selector.clone());
let new_use = if at.is_read_only(ds_aspects)? {
let usage = if at.is_read_only(ds_aspects)? {
is_ds_read_only = true;
hal::TextureUses::DEPTH_STENCIL_READ | hal::TextureUses::SAMPLED
} else {
Expand All @@ -591,16 +588,13 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
render_attachments.push(RenderAttachment {
texture_id: source_id,
selector: &view.selector,
previous_use,
new_use,
usage,
});

let old_use = previous_use.unwrap_or(new_use);
depth_stencil = Some(hal::DepthStencilAttachment {
target: hal::Attachment {
view: &view.raw,
usage: new_use,
boundary_usage: old_use..new_use,
usage,
},
depth_ops: at.depth.hal_ops(),
stencil_ops: at.stencil.hal_ops(),
Expand All @@ -626,33 +620,22 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
));
}

let boundary_usage = match color_view.source {
match color_view.source {
TextureViewSource::Native(ref source_id) => {
let previous_use = cmd_buf
.trackers
.textures
.query(source_id.value, color_view.selector.clone());
let new_use = hal::TextureUses::COLOR_TARGET;
render_attachments.push(RenderAttachment {
texture_id: source_id,
selector: &color_view.selector,
previous_use,
new_use,
usage: hal::TextureUses::COLOR_TARGET,
});

let old_use = previous_use.unwrap_or(new_use);
old_use..new_use
}
TextureViewSource::SwapChain(ref source_id) => {
assert!(used_swap_chain.is_none());
used_swap_chain = Some(source_id.clone());

let end = hal::TextureUses::empty();
let start = match at.channel.load_op {
//HACK: guess the start usage based on the load op
let start_usage = match at.channel.load_op {
LoadOp::Load => hal::TextureUses::empty(),
LoadOp::Clear => hal::TextureUses::UNINITIALIZED,
LoadOp::Load => end,
};
start..end
assert!(used_swap_chain.is_none());
used_swap_chain = Some((source_id.clone(), start_usage));
}
};

Expand All @@ -676,42 +659,32 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
return Err(RenderPassErrorInner::InvalidResolveTargetSampleCount);
}

let boundary_usage = match resolve_view.source {
match resolve_view.source {
TextureViewSource::Native(ref source_id) => {
let previous_use = cmd_buf
.trackers
.textures
.query(source_id.value, resolve_view.selector.clone());
let new_use = hal::TextureUses::COLOR_TARGET;
render_attachments.push(RenderAttachment {
texture_id: source_id,
selector: &resolve_view.selector,
previous_use,
new_use,
usage: hal::TextureUses::COLOR_TARGET,
});

let old_use = previous_use.unwrap_or(new_use);
old_use..new_use
}
TextureViewSource::SwapChain(ref source_id) => {
//HACK: guess the start usage
let start_usage = hal::TextureUses::UNINITIALIZED;
assert!(used_swap_chain.is_none());
used_swap_chain = Some(source_id.clone());
hal::TextureUses::UNINITIALIZED..hal::TextureUses::empty()
used_swap_chain = Some((source_id.clone(), start_usage));
}
};

hal_resolve_target = Some(hal::Attachment {
view: &resolve_view.raw,
usage: hal::TextureUses::COLOR_TARGET,
boundary_usage,
});
}

colors.push(hal::ColorAttachment {
target: hal::Attachment {
view: &color_view.raw,
usage: hal::TextureUses::COLOR_TARGET,
boundary_usage,
},
resolve_target: hal_resolve_target,
ops: at.channel.hal_ops(),
Expand All @@ -723,6 +696,21 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
return Err(RenderPassErrorInner::InvalidSampleCount(sample_count));
}

if let Some((ref sc_id, start_usage)) = used_swap_chain {
let &(_, ref suf_texture) = swap_chain_guard[sc_id.value]
.acquired_texture
.as_ref()
.unwrap();
let barrier = hal::TextureBarrier {
texture: std::borrow::Borrow::borrow(suf_texture),
usage: start_usage..hal::TextureUses::COLOR_TARGET,
range: wgt::ImageSubresourceRange::default(),
};
unsafe {
cmd_buf.encoder.raw.transition_textures(iter::once(barrier));
}
}

let view_data = AttachmentData {
colors: color_attachments
.iter()
Expand Down Expand Up @@ -756,7 +744,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
context,
trackers: StatefulTrackerSubset::new(A::VARIANT),
render_attachments,
used_swap_chain,
used_swap_chain: used_swap_chain.map(|(sc_id, _)| sc_id),
is_ds_read_only,
extent,
_phantom: PhantomData,
Expand All @@ -767,9 +755,28 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
mut self,
raw: &mut A::CommandEncoder,
texture_guard: &Storage<Texture<A>, id::TextureId>,
swap_chain_guard: &Storage<SwapChain<A>, id::SwapChainId>,
) -> Result<(StatefulTrackerSubset, Option<Stored<id::SwapChainId>>), RenderPassErrorInner>
{
profiling::scope!("finish", "RenderPassInfo");
unsafe {
raw.end_render_pass();
}

if let Some(ref sc_id) = self.used_swap_chain {
let &(_, ref suf_texture) = swap_chain_guard[sc_id.value]
.acquired_texture
.as_ref()
.unwrap();
let barrier = hal::TextureBarrier {
texture: std::borrow::Borrow::borrow(suf_texture),
usage: hal::TextureUses::COLOR_TARGET..hal::TextureUses::empty(),
range: wgt::ImageSubresourceRange::default(),
};
unsafe {
raw.transition_textures(iter::once(barrier));
}
}

for ra in self.render_attachments {
let texture = &texture_guard[ra.texture_id.value];
Expand All @@ -782,29 +789,11 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
ra.texture_id.value,
&ra.texture_id.ref_count,
ra.selector.clone(),
ra.new_use,
ra.usage,
)
.map_err(UsageConflict::from)?;

if let Some(usage) = ra.previous_use {
// Make the attachment tracks to be aware of the internal
// transition done by the render pass, by registering the
// previous usage as the initial state.
self.trackers
.textures
.prepend(
ra.texture_id.value,
&ra.texture_id.ref_count,
ra.selector.clone(),
usage,
)
.unwrap();
}
}

unsafe {
raw.end_render_pass();
}
Ok((self.trackers, self.used_swap_chain))
}
}
Expand Down Expand Up @@ -842,7 +831,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (device_guard, mut token) = hub.devices.read(&mut token);

let (pass_raw, trackers, query_reset_state) = {
// read-only lock guard
let (swap_chain_guard, mut token) = hub.swap_chains.read(&mut token);
let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token);

let cmd_buf =
Expand Down Expand Up @@ -886,6 +875,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
depth_stencil_attachment,
cmd_buf,
&*view_guard,
&*swap_chain_guard,
)
.map_pass_err(scope)?;

Expand Down Expand Up @@ -1206,8 +1196,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
RenderCommand::SetBlendConstant(ref color) => {
state.blend_constant = OptionalState::Set;
let array = [
color.r as f32,
color.g as f32,
color.b as f32,
color.a as f32,
];
unsafe {
raw.set_blend_constants(color);
raw.set_blend_constants(&array);
}
}
RenderCommand::SetStencilReference(value) => {
Expand Down Expand Up @@ -1738,8 +1734,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

log::trace!("Merging {:?} with the render pass", encoder_id);
let (trackers, used_swapchain) =
info.finish(raw, &*texture_guard).map_pass_err(scope)?;
let (trackers, used_swapchain) = info
.finish(raw, &*texture_guard, &*swap_chain_guard)
.map_pass_err(scope)?;

let raw_cmd_buf = unsafe {
raw.end_encoding()
.map_err(|_| RenderPassErrorInner::OutOfMemory)
Expand Down
Loading