Merge pull request #978 from ATiltedTree/use-preffered-format
wgpu: Use the preferred texture format of the surface
This commit is contained in:
commit
63bdbf817e
4 changed files with 37 additions and 33 deletions
|
|
@ -34,7 +34,7 @@ pub fn main() {
|
||||||
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
|
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
|
||||||
let surface = unsafe { instance.create_surface(&window) };
|
let surface = unsafe { instance.create_surface(&window) };
|
||||||
|
|
||||||
let (mut device, queue) = futures::executor::block_on(async {
|
let (format, (mut device, queue)) = futures::executor::block_on(async {
|
||||||
let adapter = instance
|
let adapter = instance
|
||||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||||
power_preference: wgpu::PowerPreference::HighPerformance,
|
power_preference: wgpu::PowerPreference::HighPerformance,
|
||||||
|
|
@ -43,21 +43,24 @@ pub fn main() {
|
||||||
.await
|
.await
|
||||||
.expect("Request adapter");
|
.expect("Request adapter");
|
||||||
|
|
||||||
adapter
|
(
|
||||||
.request_device(
|
adapter
|
||||||
&wgpu::DeviceDescriptor {
|
.get_swap_chain_preferred_format(&surface)
|
||||||
label: None,
|
.expect("Get preferred format"),
|
||||||
features: wgpu::Features::empty(),
|
adapter
|
||||||
limits: wgpu::Limits::default(),
|
.request_device(
|
||||||
},
|
&wgpu::DeviceDescriptor {
|
||||||
None,
|
label: None,
|
||||||
)
|
features: wgpu::Features::empty(),
|
||||||
.await
|
limits: wgpu::Limits::default(),
|
||||||
.expect("Request device")
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Request device"),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let format = wgpu::TextureFormat::Bgra8UnormSrgb;
|
|
||||||
|
|
||||||
let mut swap_chain = {
|
let mut swap_chain = {
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
|
|
@ -65,7 +68,7 @@ pub fn main() {
|
||||||
&surface,
|
&surface,
|
||||||
&wgpu::SwapChainDescriptor {
|
&wgpu::SwapChainDescriptor {
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||||
format: format,
|
format,
|
||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height,
|
height: size.height,
|
||||||
present_mode: wgpu::PresentMode::Mailbox,
|
present_mode: wgpu::PresentMode::Mailbox,
|
||||||
|
|
@ -85,7 +88,7 @@ pub fn main() {
|
||||||
// Initialize iced
|
// Initialize iced
|
||||||
let mut debug = Debug::new();
|
let mut debug = Debug::new();
|
||||||
let mut renderer =
|
let mut renderer =
|
||||||
Renderer::new(Backend::new(&mut device, Settings::default()));
|
Renderer::new(Backend::new(&mut device, Settings::default(), format));
|
||||||
|
|
||||||
let mut state = program::State::new(
|
let mut state = program::State::new(
|
||||||
controls,
|
controls,
|
||||||
|
|
|
||||||
|
|
@ -30,23 +30,24 @@ pub struct Backend {
|
||||||
|
|
||||||
impl Backend {
|
impl Backend {
|
||||||
/// Creates a new [`Backend`].
|
/// Creates a new [`Backend`].
|
||||||
pub fn new(device: &wgpu::Device, settings: Settings) -> Self {
|
pub fn new(
|
||||||
|
device: &wgpu::Device,
|
||||||
|
settings: Settings,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
|
) -> Self {
|
||||||
let text_pipeline = text::Pipeline::new(
|
let text_pipeline = text::Pipeline::new(
|
||||||
device,
|
device,
|
||||||
settings.format,
|
format,
|
||||||
settings.default_font,
|
settings.default_font,
|
||||||
settings.text_multithreading,
|
settings.text_multithreading,
|
||||||
);
|
);
|
||||||
|
|
||||||
let quad_pipeline = quad::Pipeline::new(device, settings.format);
|
let quad_pipeline = quad::Pipeline::new(device, format);
|
||||||
let triangle_pipeline = triangle::Pipeline::new(
|
let triangle_pipeline =
|
||||||
device,
|
triangle::Pipeline::new(device, format, settings.antialiasing);
|
||||||
settings.format,
|
|
||||||
settings.antialiasing,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(any(feature = "image_rs", feature = "svg"))]
|
#[cfg(any(feature = "image_rs", feature = "svg"))]
|
||||||
let image_pipeline = image::Pipeline::new(device, settings.format);
|
let image_pipeline = image::Pipeline::new(device, format);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
quad_pipeline,
|
quad_pipeline,
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,6 @@ pub use crate::Antialiasing;
|
||||||
/// [`Backend`]: crate::Backend
|
/// [`Backend`]: crate::Backend
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
/// The output format of the [`Backend`].
|
|
||||||
///
|
|
||||||
/// [`Backend`]: crate::Backend
|
|
||||||
pub format: wgpu::TextureFormat,
|
|
||||||
|
|
||||||
/// The present mode of the [`Backend`].
|
/// The present mode of the [`Backend`].
|
||||||
///
|
///
|
||||||
/// [`Backend`]: crate::Backend
|
/// [`Backend`]: crate::Backend
|
||||||
|
|
@ -68,7 +63,6 @@ impl Settings {
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
fn default() -> Settings {
|
fn default() -> Settings {
|
||||||
Settings {
|
Settings {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
|
||||||
present_mode: wgpu::PresentMode::Mailbox,
|
present_mode: wgpu::PresentMode::Mailbox,
|
||||||
internal_backend: wgpu::BackendBit::PRIMARY,
|
internal_backend: wgpu::BackendBit::PRIMARY,
|
||||||
default_font: None,
|
default_font: None,
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ pub struct Compositor {
|
||||||
queue: wgpu::Queue,
|
queue: wgpu::Queue,
|
||||||
staging_belt: wgpu::util::StagingBelt,
|
staging_belt: wgpu::util::StagingBelt,
|
||||||
local_pool: futures::executor::LocalPool,
|
local_pool: futures::executor::LocalPool,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Compositor {
|
impl Compositor {
|
||||||
|
|
@ -42,6 +43,10 @@ impl Compositor {
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let format = compatible_surface
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|surf| adapter.get_swap_chain_preferred_format(surf))?;
|
||||||
|
|
||||||
let (device, queue) = adapter
|
let (device, queue) = adapter
|
||||||
.request_device(
|
.request_device(
|
||||||
&wgpu::DeviceDescriptor {
|
&wgpu::DeviceDescriptor {
|
||||||
|
|
@ -69,12 +74,13 @@ impl Compositor {
|
||||||
queue,
|
queue,
|
||||||
staging_belt,
|
staging_belt,
|
||||||
local_pool,
|
local_pool,
|
||||||
|
format,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new rendering [`Backend`] for this [`Compositor`].
|
/// Creates a new rendering [`Backend`] for this [`Compositor`].
|
||||||
pub fn create_backend(&self) -> Backend {
|
pub fn create_backend(&self) -> Backend {
|
||||||
Backend::new(&self.device, self.settings)
|
Backend::new(&self.device, self.settings, self.format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +125,7 @@ impl iced_graphics::window::Compositor for Compositor {
|
||||||
surface,
|
surface,
|
||||||
&wgpu::SwapChainDescriptor {
|
&wgpu::SwapChainDescriptor {
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
||||||
format: self.settings.format,
|
format: self.format,
|
||||||
present_mode: self.settings.present_mode,
|
present_mode: self.settings.present_mode,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue