Skip to content

Implement webgpu textureBindingViewDimension proposal to resolve texture view heuristics errors #8014

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

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pp-rs = "0.2.1"
profiling = { version = "1.0.1", default-features = false }
quote = "1.0.38"
raw-window-handle = { version = "0.6.2", default-features = false }
rwh_05 = { version = "0.5.2", package = "raw-window-handle" } # temporary compatibility for glutin-winit
rwh_05 = { version = "0.5.2", package = "raw-window-handle" } # temporary compatibility for glutin-winit
rayon = "1.3"
regex-lite = "0.1"
renderdoc-sys = "1"
Expand Down
1 change: 1 addition & 0 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ impl GPU {
gl: wgpu_types::GlBackendOptions::default(),
noop: wgpu_types::NoopBackendOptions::default(),
},
display: None,
},
)));
state.borrow::<Instance>()
Expand Down
17 changes: 14 additions & 3 deletions examples/features/src/cube/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytemuck::{Pod, Zeroable};
use std::f32::consts;
use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, TextureViewDimension};

#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
Expand Down Expand Up @@ -149,7 +149,7 @@ impl crate::framework::Example for Example {
ty: wgpu::BindingType::Texture {
multisampled: false,
sample_type: wgpu::TextureSampleType::Uint,
view_dimension: wgpu::TextureViewDimension::D2,
view_dimension: wgpu::TextureViewDimension::D2Array,
},
count: None,
},
Expand Down Expand Up @@ -177,9 +177,20 @@ impl crate::framework::Example for Example {
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::R8Uint,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
texture_binding_view_dimension: Some(TextureViewDimension::D2Array),
view_formats: &[],
});
let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default());
let texture_view = texture.create_view(&wgpu::TextureViewDescriptor {
label: None,
format: None,
dimension: Some(wgpu::TextureViewDimension::D2Array),
usage: None,
aspect: wgpu::TextureAspect::All,
base_mip_level: 0,
mip_level_count: None,
base_array_layer: 0,
array_layer_count: Some(1),
});
queue.write_texture(
texture.as_image_copy(),
&texels,
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/cube/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ fn vs_main(

@group(0)
@binding(1)
var r_color: texture_2d<u32>;
var r_color: texture_2d_array<u32>;

@fragment
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
let tex = textureLoad(r_color, vec2<i32>(vertex.tex_coord * 256.0), 0);
let tex = textureLoad(r_color, vec2<i32>(vertex.tex_coord * 256.0), 0, 0);
let v = f32(tex.x) / 255.0;
return vec4<f32>(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0);
}
Expand Down
7 changes: 5 additions & 2 deletions examples/features/src/framework.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use wgpu::{Instance, Surface};
use wgpu::{rwh::HasDisplayHandle, Instance, Surface};
use winit::{
dpi::PhysicalSize,
event::{Event, KeyEvent, StartCause, WindowEvent},
Expand Down Expand Up @@ -268,7 +268,10 @@ impl ExampleContext {
async fn init_async<E: Example>(surface: &mut SurfaceWrapper, window: Arc<Window>) -> Self {
log::info!("Initializing wgpu...");

let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::from_env_or_default());
let mut desc = wgpu::InstanceDescriptor::from_env_or_default();
// XXX: Could also come from EventLoop before Window is created
desc.display = Some(window.display_handle().unwrap().as_raw());
let instance = wgpu::Instance::new(&desc);
surface.pre_adapter(&instance, window);

let adapter = get_adapter_with_capabilities_or_from_env(
Expand Down
57 changes: 28 additions & 29 deletions examples/features/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@
pub mod framework;
pub mod utils;

pub mod big_compute_buffers;
pub mod boids;
pub mod bunnymark;
pub mod conservative_raster;
//pub mod big_compute_buffers;
//pub mod boids;
//pub mod bunnymark;
//pub mod conservative_raster;
pub mod cube;
pub mod hello_synchronization;
pub mod hello_triangle;
pub mod hello_windows;
pub mod hello_workgroups;
pub mod mesh_shader;
pub mod mipmap;
pub mod msaa_line;
pub mod multiple_render_targets;
pub mod ray_cube_compute;
pub mod ray_cube_fragment;
pub mod ray_cube_normals;
pub mod ray_scene;
pub mod ray_shadows;
pub mod ray_traced_triangle;
pub mod render_to_texture;
pub mod repeated_compute;
pub mod shadow;
pub mod skybox;
pub mod srgb_blend;
pub mod stencil_triangles;
pub mod storage_texture;
pub mod texture_arrays;
pub mod timestamp_queries;
pub mod uniform_values;
pub mod water;
//pub mod hello_synchronization;
//pub mod hello_triangle;
//pub mod hello_windows;
//pub mod hello_workgroups;
//pub mod mipmap;
//pub mod msaa_line;
//pub mod multiple_render_targets;
//pub mod ray_cube_compute;
//pub mod ray_cube_fragment;
//pub mod ray_cube_normals;
//pub mod ray_scene;
//pub mod ray_shadows;
//pub mod ray_traced_triangle;
//pub mod render_to_texture;
//pub mod repeated_compute;
//pub mod shadow;
//pub mod skybox;
//pub mod srgb_blend;
//pub mod stencil_triangles;
//pub mod storage_texture;
//pub mod texture_arrays;
//pub mod timestamp_queries;
//pub mod uniform_values;
//pub mod water;

#[cfg(test)]
wgpu_test::gpu_test_main!();
4 changes: 4 additions & 0 deletions examples/features/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct ExampleDesc {
}

const EXAMPLES: &[ExampleDesc] = &[
/*
ExampleDesc {
name: "big_compute_buffers",
function: wgpu_examples::big_compute_buffers::main,
Expand All @@ -32,12 +33,14 @@ const EXAMPLES: &[ExampleDesc] = &[
webgl: false, // No conservative raster
webgpu: false, // No conservative raster
},
*/
ExampleDesc {
name: "cube",
function: wgpu_examples::cube::main,
webgl: true,
webgpu: true,
},
/*
ExampleDesc {
name: "hello_synchronization",
function: wgpu_examples::hello_synchronization::main,
Expand Down Expand Up @@ -188,6 +191,7 @@ const EXAMPLES: &[ExampleDesc] = &[
webgl: false,
webgpu: false,
},
*/
];

fn get_example_name() -> Option<String> {
Expand Down
1 change: 1 addition & 0 deletions tests/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub fn initialize_instance(backends: wgpu::Backends, params: &TestParameters) ->
// TODO(https://github.com/gfx-rs/wgpu/issues/7119): Enable noop backend?
noop: wgpu::NoopBackendOptions::default(),
},
display: None,
})
}

Expand Down
1 change: 1 addition & 0 deletions tests/tests/wgpu-validation/api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mod request_adapter_error {
flags: wgpu::InstanceFlags::default(),
memory_budget_thresholds: wgpu::MemoryBudgetThresholds::default(),
backend_options: wgpu::BackendOptions::default(),
display: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ impl Device {
sample_count: desc.sample_count,
dimension: desc.dimension,
format: desc.format,
texture_binding_view_dimension: desc.texture_binding_view_dimension,
usage: hal_usage,
memory_flags: hal::MemoryFlags::empty(),
view_formats: hal_view_formats,
Expand Down
5 changes: 5 additions & 0 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use alloc::{
};

use hashbrown::HashMap;
use raw_window_handle::DisplayHandle;
use thiserror::Error;
use wgt::error::{ErrorType, WebGpuError};

Expand Down Expand Up @@ -131,6 +132,10 @@ impl Instance {
flags: self.flags,
memory_budget_thresholds: instance_desc.memory_budget_thresholds,
backend_options: instance_desc.backend_options.clone(),
display: instance_desc
.display
// XXX: This assigns a bogus lifetime. hal::InstanceDescriptor should also take Raw?
.map(|r| unsafe { DisplayHandle::borrow_raw(r) }),
};

use hal::Instance as _;
Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ impl Surface {
mip_level_count: 1,
format: config.format,
dimension: wgt::TextureDimension::D2,
texture_binding_view_dimension: None,
usage: config.usage,
view_formats: config.view_formats,
};
Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ gles = [
"dep:hashbrown",
"dep:js-sys",
"dep:khronos-egl",
"dep:wayland-sys",
"dep:libloading",
"dep:log",
"dep:ndk-sys",
Expand Down Expand Up @@ -245,6 +246,9 @@ renderdoc-sys = { workspace = true, optional = true }
[target.'cfg(unix)'.dependencies]
# Backend: Vulkan
libc = { workspace = true, optional = true }
# backend: GLES
# XXX: Using crate to copy from glutin. Better yet, use wayland-client or replace entire backend with glutin entirely.
wayland-sys = { version = "0.31", features = ["client", "dlopen", "egl"], optional = true }

#########################
### Platform: Windows ###
Expand Down
7 changes: 5 additions & 2 deletions wgpu-hal/examples/halmark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,24 @@ struct Example<A: hal::Api> {

impl<A: hal::Api> Example<A> {
fn init(window: &winit::window::Window) -> Result<Self, Box<dyn std::error::Error>> {
// XXX: Could be from the EventLoop as well
let raw_display_handle = window.display_handle()?;

let instance_desc = hal::InstanceDescriptor {
name: "example",
flags: wgpu_types::InstanceFlags::from_build_config().with_env(),
memory_budget_thresholds: wgpu_types::MemoryBudgetThresholds::default(),
// Can't rely on having DXC available, so use FXC instead
backend_options: wgpu_types::BackendOptions::default(),
display: Some(raw_display_handle),
};
let instance = unsafe { A::Instance::init(&instance_desc)? };
let surface = {
let raw_window_handle = window.window_handle()?.as_raw();
let raw_display_handle = window.display_handle()?.as_raw();

unsafe {
instance
.create_surface(raw_display_handle, raw_window_handle)
.create_surface(raw_display_handle.as_raw(), raw_window_handle)
.unwrap()
}
};
Expand Down
8 changes: 6 additions & 2 deletions wgpu-hal/examples/ray-traced-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ impl<A: hal::Api> Example<A> {
log::info!("using index buffer")
}

// XXX: Could be from the EventLoop as well
let raw_display_handle = window.display_handle()?;

let instance_desc = hal::InstanceDescriptor {
name: "example",
flags: wgpu_types::InstanceFlags::default(),
Expand All @@ -245,15 +248,16 @@ impl<A: hal::Api> Example<A> {
},
..Default::default()
},
// XXX: Coudla
display: Some(raw_display_handle),
};
let instance = unsafe { A::Instance::init(&instance_desc)? };
let surface = {
let raw_window_handle = window.window_handle()?.as_raw();
let raw_display_handle = window.display_handle()?.as_raw();

unsafe {
instance
.create_surface(raw_display_handle, raw_window_handle)
.create_surface(raw_display_handle.as_raw(), raw_window_handle)
.unwrap()
}
};
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ impl super::Adapter {
unsafe { gl.get_parameter_i32(glow::MAX_TEXTURE_MAX_ANISOTROPY_EXT) } as u32;
downlevel_flags.set(wgt::DownlevelFlags::ANISOTROPIC_FILTERING, max_aniso >= 16);
}

downlevel_flags.set(
wgt::DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED,
!(cfg!(any(webgl, Emscripten)) || is_angle),
Expand Down
Loading
Loading