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

Release wgpu-hal-0.12.3 #2411

Merged
merged 8 commits into from
Jan 21, 2022
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## wgpu-hal-0.12.3, deno-webgpu-? (2022-01-20)
- Metal:
- preserve vertex invariance
- Vulkan
- fix stencil read/write masks
- Gles:
- reset index binding properly
- DX12:
- fix copies into 1D textures

## wgpu-core-0.12.2, wgpu-hal-0.12.2 (2022-01-10)
- fix tracy compile error
- fix buffer binding limits beyond 2Gb
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

14 changes: 7 additions & 7 deletions cts_runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ publish = false
resolver = "2"

[dependencies]
deno_console = { git = "https://github.com/denoland/deno", rev = "ca75752e5a9499a0a997809f02b18c2ba1ecd58d" }
deno_core = { git = "https://github.com/denoland/deno", rev = "ca75752e5a9499a0a997809f02b18c2ba1ecd58d" }
deno_timers = { git = "https://github.com/denoland/deno", rev = "ca75752e5a9499a0a997809f02b18c2ba1ecd58d" }
deno_url = { git = "https://github.com/denoland/deno", rev = "ca75752e5a9499a0a997809f02b18c2ba1ecd58d" }
deno_web = { git = "https://github.com/denoland/deno", rev = "ca75752e5a9499a0a997809f02b18c2ba1ecd58d" }
deno_webidl = { git = "https://github.com/denoland/deno", rev = "ca75752e5a9499a0a997809f02b18c2ba1ecd58d" }
deno_console = "0.32.0"
deno_core = "0.114.0"
deno_timers = "0.30.0"
deno_url = "0.32.0"
deno_web = "0.63.0"
deno_webidl = "0.32.0"
deno_webgpu = { path = "../deno_webgpu" }
tokio = { version = "1.10.0", features = ["full"] }
tokio = { version = "1.15.0", features = ["full"] }
termcolor = "1.1.2"
19 changes: 15 additions & 4 deletions cts_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
rc::Rc,
};

use deno_core::error::anyhow;
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::located_script_name;
use deno_core::resolve_url_or_path;
Expand Down Expand Up @@ -41,7 +41,7 @@ async fn run() -> Result<(), AnyError> {
deno_console::init(),
deno_url::init(),
deno_web::init(BlobStore::default(), None),
deno_timers::init::<deno_timers::NoTimersPermission>(),
deno_timers::init::<Permissions>(),
deno_webgpu::init(true),
extension(),
],
Expand All @@ -56,9 +56,9 @@ async fn run() -> Result<(), AnyError> {
isolate
.op_state()
.borrow_mut()
.put(deno_timers::NoTimersPermission);
.put(Permissions{});

let mod_id = isolate.load_module(&specifier, None).await?;
let mod_id = isolate.load_main_module(&specifier, None).await?;
let mod_rx = isolate.mod_evaluate(mod_id);

let rx = tokio::spawn(async move {
Expand Down Expand Up @@ -149,3 +149,14 @@ fn red_bold<S: AsRef<str>>(s: S) -> impl fmt::Display {
style_spec.set_fg(Some(Red)).set_bold(true);
style(s, style_spec)
}

// NOP permissions
struct Permissions;

impl deno_timers::TimersPermission for Permissions {
fn allow_hrtime(&mut self) -> bool {
false
}

fn check_unstable(&self, _state: &deno_core::OpState, _api_name: &'static str) {}
}
2 changes: 1 addition & 1 deletion deno_webgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/gfx-rs/wgpu"
description = "WebGPU implementation for Deno"

[dependencies]
deno_core = { git = "https://github.com/denoland/deno", rev = "ca75752e5a9499a0a997809f02b18c2ba1ecd58d" }
deno_core = "0.114.0"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.10", features = ["full"] }
wgpu-core = { path = "../wgpu-core", features = ["trace", "replay", "serde"] }
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub async fn op_webgpu_request_adapter(

let descriptor = wgpu_core::instance::RequestAdapterOptions {
power_preference: match args.power_preference {
Some(power_preference) => power_preference.into(),
Some(power_preference) => power_preference,
None => PowerPreference::default(),
},
force_fallback_adapter: args.force_fallback_adapter,
Expand Down
10 changes: 5 additions & 5 deletions deno_webgpu/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ impl TryFrom<GpuDepthStencilState> for wgpu_types::DepthStencilState {
Ok(wgpu_types::DepthStencilState {
format: state.format,
depth_write_enabled: state.depth_write_enabled,
depth_compare: state.depth_compare.into(),
depth_compare: state.depth_compare,
stencil: wgpu_types::StencilState {
front: state.stencil_front.into(),
back: state.stencil_back.into(),
front: state.stencil_front,
back: state.stencil_back,
read_mask: state.stencil_read_mask,
write_mask: state.stencil_write_mask,
},
Expand Down Expand Up @@ -322,7 +322,7 @@ pub fn op_webgpu_create_render_pipeline(
let mut targets = Vec::with_capacity(fragment.targets.len());

for target in fragment.targets {
targets.push(target.try_into()?);
targets.push(target);
}

Some(wgpu_core::pipeline::FragmentState {
Expand Down Expand Up @@ -356,7 +356,7 @@ pub fn op_webgpu_create_render_pipeline(
},
primitive: args.primitive.into(),
depth_stencil: args.depth_stencil.map(TryInto::try_into).transpose()?,
multisample: args.multisample.into(),
multisample: args.multisample,
fragment,
multiview: None,
};
Expand Down
3 changes: 1 addition & 2 deletions wgpu-core/src/command/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{num::NonZeroU32, ops::Range};
#[cfg(feature = "trace")]
use crate::device::trace::Command as TraceCommand;
use crate::{
align_to,
command::CommandBuffer,
device::Device,
get_lowest_common_denom,
Expand All @@ -14,7 +13,7 @@ use crate::{
track::{ResourceTracker, TextureSelector, TextureState},
};

use hal::CommandEncoder as _;
use hal::{auxil::align_to, CommandEncoder as _};
use thiserror::Error;
use wgt::{BufferAddress, BufferSize, BufferUsages, ImageSubresourceRange, TextureAspect};

Expand Down
3 changes: 1 addition & 2 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[cfg(feature = "trace")]
use crate::device::trace::Action;
use crate::{
align_to,
command::{
extract_texture_selector, validate_linear_texture_data, validate_texture_copy_range,
ClearError, CommandBuffer, CopySide, ImageCopyTexture, TransferError,
Expand Down Expand Up @@ -415,7 +414,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device.alignments.buffer_copy_pitch.get() as u32,
format_desc.block_size as u32,
);
let stage_bytes_per_row = align_to(
let stage_bytes_per_row = hal::auxil::align_to(
format_desc.block_size as u32 * width_blocks,
bytes_per_row_alignment,
);
Expand Down
8 changes: 0 additions & 8 deletions wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,6 @@ pub(crate) fn get_greatest_common_divisor(mut a: u32, mut b: u32) -> u32 {
}
}

#[inline]
pub(crate) fn align_to(value: u32, alignment: u32) -> u32 {
match value % alignment {
0 => value,
other => value - other + alignment,
}
}

#[test]
fn test_lcd() {
assert_eq!(get_lowest_common_denom(2, 2), 2);
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wgpu-hal"
version = "0.12.2"
version = "0.12.3"
authors = ["wgpu developers"]
edition = "2018"
description = "WebGPU hardware abstraction layer"
Expand Down
19 changes: 5 additions & 14 deletions wgpu-hal/examples/halmark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Example<A: hal::Api> {
pipeline: A::RenderPipeline,
bunnies: Vec<Locals>,
local_buffer: A::Buffer,
local_alignment: wgt::BufferAddress,
local_alignment: u32,
global_buffer: A::Buffer,
sampler: A::Sampler,
texture: A::Texture,
Expand Down Expand Up @@ -376,22 +376,13 @@ impl<A: hal::Api> Example<A> {
buffer
};

fn align_to(
value: wgt::BufferAddress,
alignment: wgt::BufferAddress,
) -> wgt::BufferAddress {
match value % alignment {
0 => value,
other => value - other + alignment,
}
}
let local_alignment = align_to(
mem::size_of::<Locals>() as _,
capabilities.limits.min_uniform_buffer_offset_alignment as _,
let local_alignment = hal::auxil::align_to(
mem::size_of::<Locals>() as u32,
capabilities.limits.min_uniform_buffer_offset_alignment,
);
let local_buffer_desc = hal::BufferDescriptor {
label: Some("local"),
size: (MAX_BUNNIES as wgt::BufferAddress) * local_alignment,
size: (MAX_BUNNIES as wgt::BufferAddress) * (local_alignment as wgt::BufferAddress),
usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::UNIFORM,
memory_flags: hal::MemoryFlags::PREFER_COHERENT,
};
Expand Down
11 changes: 11 additions & 0 deletions wgpu-hal/src/auxil/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ pub fn map_naga_stage(stage: naga::ShaderStage) -> wgt::ShaderStages {
}
}

pub fn align_to(value: u32, alignment: u32) -> u32 {
if alignment.is_power_of_two() {
(value + alignment - 1) & !(alignment - 1)
} else {
match value % alignment {
0 => value,
other => value - other + alignment,
}
}
}

impl crate::CopyExtent {
pub fn min(&self, other: &Self) -> Self {
Self {
Expand Down
72 changes: 36 additions & 36 deletions wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,40 @@ fn make_box(origin: &wgt::Origin3d, size: &crate::CopyExtent) -> d3d12::D3D12_BO
}
}

impl crate::BufferTextureCopy {
fn to_subresource_footprint(
&self,
format: wgt::TextureFormat,
) -> d3d12::D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
let desc = format.describe();
d3d12::D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
Offset: self.buffer_layout.offset,
Footprint: d3d12::D3D12_SUBRESOURCE_FOOTPRINT {
Format: conv::map_texture_format(format),
Width: self.size.width,
Height: self
.buffer_layout
.rows_per_image
.map_or(self.size.height, |count| {
count.get() * desc.block_dimensions.1 as u32
}),
Depth: self.size.depth,
RowPitch: {
let actual = match self.buffer_layout.bytes_per_row {
Some(count) => count.get(),
// this may happen for single-line updates
None => {
(self.size.width / desc.block_dimensions.0 as u32)
* desc.block_size as u32
}
};
crate::auxil::align_to(actual, d3d12::D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
},
},
}
}
}

impl super::Temp {
fn prepare_marker(&mut self, marker: &str) -> (&[u16], u32) {
self.marker.clear();
Expand Down Expand Up @@ -458,28 +492,10 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
Type: d3d12::D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
u: mem::zeroed(),
};
let raw_format = conv::map_texture_format(dst.format);

let block_size = dst.format.describe().block_dimensions.0 as u32;
for r in regions {
let src_box = make_box(&wgt::Origin3d::ZERO, &r.size);
*src_location.u.PlacedFootprint_mut() = d3d12::D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
Offset: r.buffer_layout.offset,
Footprint: d3d12::D3D12_SUBRESOURCE_FOOTPRINT {
Format: raw_format,
Width: r.size.width,
Height: r
.buffer_layout
.rows_per_image
.map_or(r.size.height, |count| count.get() * block_size),
Depth: r.size.depth,
RowPitch: r.buffer_layout.bytes_per_row.map_or(0, |count| {
count.get().max(d3d12::D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
}),
},
};
*src_location.u.PlacedFootprint_mut() = r.to_subresource_footprint(dst.format);
*dst_location.u.SubresourceIndex_mut() = dst.calc_subresource_for_copy(&r.texture_base);

list.CopyTextureRegion(
&dst_location,
r.texture_base.origin.x,
Expand Down Expand Up @@ -511,26 +527,10 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
Type: d3d12::D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
u: mem::zeroed(),
};
let raw_format = conv::map_texture_format(src.format);

let block_size = src.format.describe().block_dimensions.0 as u32;
for r in regions {
let src_box = make_box(&r.texture_base.origin, &r.size);
*src_location.u.SubresourceIndex_mut() = src.calc_subresource_for_copy(&r.texture_base);
*dst_location.u.PlacedFootprint_mut() = d3d12::D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
Offset: r.buffer_layout.offset,
Footprint: d3d12::D3D12_SUBRESOURCE_FOOTPRINT {
Format: raw_format,
Width: r.size.width,
Height: r
.buffer_layout
.rows_per_image
.map_or(r.size.height, |count| count.get() * block_size),
Depth: r.size.depth,
RowPitch: r.buffer_layout.bytes_per_row.map_or(0, |count| count.get()),
},
};

*dst_location.u.PlacedFootprint_mut() = r.to_subresource_footprint(src.format);
list.CopyTextureRegion(&dst_location, 0, 0, 0, &src_location, &src_box);
}
}
Expand Down
5 changes: 4 additions & 1 deletion wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl super::Queue {
}
}

unsafe fn reset_state(&self, gl: &glow::Context) {
unsafe fn reset_state(&mut self, gl: &glow::Context) {
gl.use_program(None);
gl.bind_framebuffer(glow::FRAMEBUFFER, None);
gl.disable(glow::DEPTH_TEST);
Expand All @@ -69,6 +69,9 @@ impl super::Queue {
if self.features.contains(wgt::Features::DEPTH_CLIP_CONTROL) {
gl.disable(glow::DEPTH_CLAMP);
}

gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, None);
self.current_index_buffer = None;
}

unsafe fn set_attachment(
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,11 @@ impl super::PrivateCapabilities {
supports_depth_clip_control: device
.supports_feature_set(MTLFeatureSet::iOS_GPUFamily4_v1)
|| os_is_mac,
supports_preserve_invariance: if os_is_mac {
Self::version_at_least(major, minor, 11, 0)
} else {
Self::version_at_least(major, minor, 13, 0)
},
}
}

Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl super::Device {
let options = mtl::CompileOptions::new();
options.set_language_version(self.shared.private_caps.msl_version);

if self.shared.private_caps.supports_preserve_invariance {
options.set_preserve_invariance(true);
}

let library = self
.shared
.device
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ struct PrivateCapabilities {
supports_arrays_of_textures_write: bool,
supports_mutability: bool,
supports_depth_clip_control: bool,
supports_preserve_invariance: bool,
}

#[derive(Clone, Debug)]
Expand Down
Loading