create surface on same thread?
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
|
flamegraph.svg
|
||||||
|
perf.data*
|
||||||
|
|||||||
491
flamegraph.svg
491
flamegraph.svg
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 201 KiB |
BIN
perf.data.old
BIN
perf.data.old
Binary file not shown.
@@ -13,10 +13,7 @@ use std::{
|
|||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
use voxel::VoxelPipeline;
|
use voxel::VoxelPipeline;
|
||||||
use winit::{
|
use winit::dpi::PhysicalSize;
|
||||||
dpi::PhysicalSize,
|
|
||||||
window::{Fullscreen, Window},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Renderer<'a> {
|
pub struct Renderer<'a> {
|
||||||
size: Vector2<u32>,
|
size: Vector2<u32>,
|
||||||
@@ -34,23 +31,11 @@ pub struct Renderer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Renderer<'a> {
|
impl<'a> Renderer<'a> {
|
||||||
pub fn new(window: Arc<Window>) -> Self {
|
pub fn new(
|
||||||
let fullscreen = false;
|
instance: wgpu::Instance,
|
||||||
if fullscreen {
|
surface: wgpu::Surface<'a>,
|
||||||
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
|
size: PhysicalSize<u32>,
|
||||||
}
|
) -> Self {
|
||||||
|
|
||||||
let size = window.inner_size();
|
|
||||||
|
|
||||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
|
||||||
backends: wgpu::Backends::PRIMARY,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
let surface = instance
|
|
||||||
.create_surface(window)
|
|
||||||
.expect("Could not create window surface!");
|
|
||||||
|
|
||||||
let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
|
let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
|
||||||
power_preference: wgpu::PowerPreference::default(),
|
power_preference: wgpu::PowerPreference::default(),
|
||||||
compatible_surface: Some(&surface),
|
compatible_surface: Some(&surface),
|
||||||
|
|||||||
@@ -34,10 +34,21 @@ pub struct CreateVoxelGrid {
|
|||||||
impl Renderer<'_> {
|
impl Renderer<'_> {
|
||||||
pub fn spawn(window: Arc<Window>) -> (RendererChannel, JoinHandle<()>) {
|
pub fn spawn(window: Arc<Window>) -> (RendererChannel, JoinHandle<()>) {
|
||||||
let (s, mut r) = channel();
|
let (s, mut r) = channel();
|
||||||
|
|
||||||
|
let size = window.inner_size();
|
||||||
|
|
||||||
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
|
backends: wgpu::Backends::PRIMARY,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
|
let surface = instance
|
||||||
|
.create_surface(window)
|
||||||
|
.expect("Could not create window surface!");
|
||||||
(
|
(
|
||||||
s,
|
s,
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
Self::new(window.clone()).start(&mut r);
|
Self::new(instance, surface, size).start(&mut r);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user