Skip to content

Commit

Permalink
instance creation takes instance descriptor now by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Jan 3, 2025
1 parent f87ff52 commit efb92cb
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion benches/benches/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl DeviceState {
wgpu::Backends::all()
};

let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends: wgpu::util::backend_bits_from_env().unwrap_or(base_backend),
flags: wgpu::InstanceFlags::empty(),
dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env()
Expand Down
2 changes: 1 addition & 1 deletion examples/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ 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::util::instance_descriptor_from_env());
let instance = wgpu::Instance::new(&wgpu::util::instance_descriptor_from_env());
surface.pre_adapter(&instance, window);

let adapter = get_adapter_with_capabilities_or_from_env(
Expand Down
2 changes: 1 addition & 1 deletion examples/src/hello_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
size.width = size.width.max(1);
size.height = size.height.max(1);

let instance = wgpu::Instance::new(wgpu::util::instance_descriptor_from_env());
let instance = wgpu::Instance::new(&wgpu::util::instance_descriptor_from_env());

let surface = instance.create_surface(&window).unwrap();
let adapter = instance
Expand Down
2 changes: 1 addition & 1 deletion examples/src/timestamp_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Queries {
async fn run() {
// Instantiates instance of wgpu
let backends = wgpu::util::backend_bits_from_env().unwrap_or_default();
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends,
flags: wgpu::InstanceFlags::from_build_config().with_env(),
dx12_shader_compiler: wgpu::Dx12Compiler::default(),
Expand Down
2 changes: 1 addition & 1 deletion player/src/bin/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() {
.build(&event_loop)
.unwrap();

let global = wgc::global::Global::new("player", wgt::InstanceDescriptor::default());
let global = wgc::global::Global::new("player", &wgt::InstanceDescriptor::default());
let mut command_buffer_id_manager = wgc::identity::IdentityManager::new();

#[cfg(feature = "winit")]
Expand Down
2 changes: 1 addition & 1 deletion player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Corpus {

let global = wgc::global::Global::new(
"test",
wgt::InstanceDescriptor {
&wgt::InstanceDescriptor {
backends: backend.into(),
flags: wgt::InstanceFlags::debugging(),
dx12_shader_compiler: wgt::Dx12Compiler::Fxc,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn initialize_instance(backends: wgpu::Backends, force_fxc: bool) -> Instanc
wgpu::util::dx12_shader_compiler_from_env().unwrap_or(wgpu::Dx12Compiler::StaticDxc)
};
let gles_minor_version = wgpu::util::gles_minor_version_from_env().unwrap_or_default();
Instance::new(wgpu::InstanceDescriptor {
Instance::new(&wgpu::InstanceDescriptor {
backends,
flags: wgpu::InstanceFlags::debugging().with_env(),
dx12_shader_compiler,
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/multi-instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

async fn get() -> wgpu::Adapter {
let adapter = {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends: wgpu::util::backend_bits_from_env().unwrap_or_default(),
..Default::default()
});
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Global {
}

impl Global {
pub fn new(name: &str, instance_desc: wgt::InstanceDescriptor) -> Self {
pub fn new(name: &str, instance_desc: &wgt::InstanceDescriptor) -> Self {
profiling::scope!("Global::new");
Self {
instance: Instance::new(name, instance_desc),
Expand Down
10 changes: 5 additions & 5 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct Instance {
}

impl Instance {
pub fn new(name: &str, instance_desc: wgt::InstanceDescriptor) -> Self {
pub fn new(name: &str, instance_desc: &wgt::InstanceDescriptor) -> Self {
fn init<A: HalApi>(
_: A,
instance_desc: &wgt::InstanceDescriptor,
Expand Down Expand Up @@ -99,13 +99,13 @@ impl Instance {
let mut instance_per_backend = Vec::new();

#[cfg(vulkan)]
init(hal::api::Vulkan, &instance_desc, &mut instance_per_backend);
init(hal::api::Vulkan, instance_desc, &mut instance_per_backend);
#[cfg(metal)]
init(hal::api::Metal, &instance_desc, &mut instance_per_backend);
init(hal::api::Metal, instance_desc, &mut instance_per_backend);
#[cfg(dx12)]
init(hal::api::Dx12, &instance_desc, &mut instance_per_backend);
init(hal::api::Dx12, instance_desc, &mut instance_per_backend);
#[cfg(gles)]
init(hal::api::Gles, &instance_desc, &mut instance_per_backend);
init(hal::api::Gles, instance_desc, &mut instance_per_backend);

Self {
name: name.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion wgpu-info/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct GpuReport {

impl GpuReport {
pub fn generate() -> Self {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends: wgpu::util::backend_bits_from_env().unwrap_or_default(),
flags: wgpu::InstanceFlags::debugging().with_env(),
dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env()
Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Default for Instance {
/// If no backend feature for the active target platform is enabled,
/// this method will panic, see [`Instance::enabled_backend_features()`].
fn default() -> Self {
Self::new(InstanceDescriptor::default())
Self::new(&InstanceDescriptor::default())
}
}

Expand Down Expand Up @@ -113,7 +113,7 @@ impl Instance {
/// If no backend feature for the active target platform is enabled,
/// this method will panic, see [`Instance::enabled_backend_features()`].
#[allow(unreachable_code)]
pub fn new(_instance_desc: InstanceDescriptor) -> Self {
pub fn new(_instance_desc: &InstanceDescriptor) -> Self {
if Self::enabled_backend_features().is_empty() {
panic!(
"No wgpu backend feature that is implemented for the target platform was enabled. \
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl InterfaceTypes for ContextWgpuCore {
}

impl dispatch::InstanceInterface for ContextWgpuCore {
fn new(desc: wgt::InstanceDescriptor) -> Self
fn new(desc: &wgt::InstanceDescriptor) -> Self
where
Self: Sized,
{
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait InterfaceTypes {
}

pub trait InstanceInterface: CommonTraits {
fn new(desc: crate::InstanceDescriptor) -> Self
fn new(desc: &wgt::InstanceDescriptor) -> Self
where
Self: Sized;

Expand Down
5 changes: 3 additions & 2 deletions wgpu/src/util/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ pub async fn is_browser_webgpu_supported() -> bool {
/// this method will panic, see [`Instance::enabled_backend_features()`].
#[allow(unused_mut)]
pub async fn new_instance_with_webgpu_detection(
mut instance_desc: wgt::InstanceDescriptor,
instance_desc: impl std::ops::Deref<Target = wgt::InstanceDescriptor>,
) -> crate::Instance {
let mut instance_desc = instance_desc.clone();
if instance_desc
.backends
.contains(wgt::Backends::BROWSER_WEBGPU)
Expand All @@ -209,5 +210,5 @@ pub async fn new_instance_with_webgpu_detection(
instance_desc.backends.remove(wgt::Backends::BROWSER_WEBGPU);
}

crate::Instance::new(instance_desc)
crate::Instance::new(&instance_desc)
}

0 comments on commit efb92cb

Please sign in to comment.